Skip to content

Instantly share code, notes, and snippets.

@i-am-tom
i-am-tom / MapRecord.purs
Last active Nov 9, 2020
MapRecord for PureScript, with and without comments!
View MapRecord.purs
module MapRecordWithComments where
-- | Type-level Tomfoolery. A million thankyous to @kcsongor and his
-- | unparallelled patience with me while I try to figure this stuff
-- | out.
import Prelude (($), (+), (<>), discard, show)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
View Main.purs
module Main where
import Prelude
import Effect.Console (logShow)
import TryPureScript (render, withConsole)
-- Declare the recursive type.
data Peano = Z | S Peano
-- This allows us to print the type.
@i-am-tom
i-am-tom / Main.hs
Created Sep 22, 2020
A warning to all
View Main.hs
{-# LANGUAGE DataKinds #-}
{-# LANguAGE FlexibleContexts #-}
{-# LAnguaGE FlexibleInstances #-}
{-# LanguagE KindSignatures #-}
{-# language MultiParamTypeClasses #-}
import GHC.TypeLits (Symbol)
class Warning (message :: Symbol) x
instance Warning (message :: Symbol) x
@i-am-tom
i-am-tom / Main.hs
Last active Sep 22, 2020
Monoids in the category of thendofunctors
View Main.hs
{-# LANguage FlexibleContexts #-}
{-# laNguAGe FlexibleInstances #-}
{-# languAGE FunctionalDependencies #-}
{-# LANguagE RebindableSyntax #-}
{-# LANguAge ScopedTypeVariables #-}
{-# LAnGuage TypeFamilies #-}
{-# LangUaGe UndecidableInstances #-}
module Control.Monad.Search where
import Data.Function ((&))
@i-am-tom
i-am-tom / FizzBuzz.hs
Last active Sep 20, 2020
Arguably the fastest implementation of FizzBuzz ever written.
View FizzBuzz.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnsaturatedTypeFamilies #-}
import GHC.TypeLits
import Prelude hiding (Functor, Semigroup)
type Main = (Fizz <> Buzz) <$> (0 `To` 100)
@i-am-tom
i-am-tom / Trolling.hs
Created May 11, 2019
Ramda-style composition where the first function must receive all arguments.
View Trolling.hs
{-# LAnguage FlexibleInstances #-}
{-# LANGuage FunctionalDependencies #-}
{-# LANGUAge GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
module Trolling where
---------------------------------------------------------------------
-- VARIADIC COMPOSITION IN HASKELL (A LA RAMDA.JS).
--
-- In Haskell, we typeically think of the composition operator (or
@i-am-tom
i-am-tom / bot.hs
Last active Jul 9, 2020 — forked from geekingfrog/bot.hs
Pour monsieur Charvet
View bot.hs
{-# OPTIONS_GHC -Wall -Wextra #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Functor.Product (Product (..))
import Data.Barbie
@i-am-tom
i-am-tom / Main.hs
Created Jul 6, 2020
Variadic number functions
View Main.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
------------------------------
-- PROBAT
main :: IO ()
View comonads.js
const Day = ({ get, left, right }) => {
const map = f => Day ({
get: f (extract()),
left, right
})
const extend = f =>
Day ({
get: (left, right) => f (Day ({ get, left, right })),
@i-am-tom
i-am-tom / Cursed.hs
Created May 22, 2020
An oldie-but-goldie
View Cursed.hs
{-# OPTIONS_GHC -Wno-missing-methods #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE PolyKinds #-}