Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / gist:c0efcea739f2d549df0a
Last active August 29, 2015 14:05
Diff impl for Either and (,)
data Zipper t a = Zipper { diff :: D t a, here :: a }
deriving instance Diff t => Functor (Zipper t)
class (Functor t, Functor (D t)) => Diff t where
data D t :: * -> *
inTo :: t a -> t (Zipper t a)
outOf :: Zipper t a -> t a
instance Diff ((,) x) where
@tel
tel / dbp.hs
Last active August 29, 2015 14:05
de Bruijn playground
{-# LANGUAGE GADTs #-}
{-
Consider the standard "finally tagless" de Bruijn encoded lambda
calculus.
-}
class Db r where
@tel
tel / Zipper.hs
Created September 1, 2014 14:05
Infinitely derivative zippers
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableInstances, DeriveFunctor, TypeOperators #-}
{-# LANGUAGE FlexibleContexts, StandaloneDeriving, ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies, RankNTypes, GADTs, DefaultSignatures #-}
module Zippers where
import Control.Applicative
class Functor f => Comonad f where
@tel
tel / T.hs
Last active August 29, 2015 14:06
Transducers with explicit local state
{-# LANGUAGE GADTs, RankNTypes #-}
import Control.Applicative
import Control.Category
import Data.List (foldl')
import Data.Profunctor
import Prelude hiding ((.), id)
-- | Explicit state-passing Moore machine
data Moore i o where
@tel
tel / keybase.md
Created September 23, 2014 18:17

Keybase proof

I hereby claim:

  • I am tel on github.
  • I am tel (https://keybase.io/tel) on keybase.
  • I have a public key whose fingerprint is C8D6 8612 BD85 2998 F35E 5339 0675 90FD 6502 8C09

To claim this, I am signing this object:

@tel
tel / FailArz.hs
Created October 19, 2014 21:34
Data constructor ‘SfSwitch’ cannot be GADT-like in its *kind* arguments
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GADTs #-}
data Sv u where
E :: u -> Sv u
S :: u -> Sv u
data Sf (coupled :: Bool)
@tel
tel / TransformerExample.hs
Last active August 29, 2015 14:08
Monad Transformers Example (using mtl)
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module TransformerExample where
{-
We'll layer StateT and IO together in order to track the most recent
response received in interactive communication with the user.
@tel
tel / ListT.hs
Created November 6, 2014 23:39
ListT done right
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE OverloadedLists #-}
module ListT where
import Control.Applicative
import Control.Monad
import Control.Monad.Trans
import Data.Monoid
@tel
tel / BiAST.hs
Last active August 29, 2015 14:10
Bidirectional, open-recursion AST
data Ty = Bool | Arr Ty Ty deriving (Eq, Show)
data IExpr c i
= Var Int
| App i c
| Annot c Ty
| If c i i
| ETrue
| EFalse
@tel
tel / gist:e1f040a4e42887e6ab7a
Created December 2, 2014 14:51
Num-in-Reader
-- We'll use the instance of Applicative for ((->) a) below
instance Num b => Num (a -> b) where
(+) = liftA2 (+)
(*) = liftA2 (*)
(-) = liftA2 (-)
negate = fmap negate
signum = fmap signum
abs = fmap abs