Skip to content

Instantly share code, notes, and snippets.

View dorchard's full-sized avatar

Dominic Orchard dorchard

View GitHub Profile
@dorchard
dorchard / gist:4df935ebad0807c47b80
Last active August 29, 2015 14:04
type level implicit parameters example (speculation)
Consider a data type representing syntax trees.
> data Expr = BinOp Expr Expr | Unop Expr
> data Stmt = Seq Stmt Stmt | Assign String Expr
Let's say I want this in a module, but I also want to be able to arbitrarily extend this AST type
in modules that import it. So, I add an extra constructor and a type parameter
to all the data type definitions:
> data Expr ext = BinOp (Expr ext) (Expr ext) | Unop (Expr ext) | Ext ext
@dorchard
dorchard / gist:4132742
Created November 22, 2012 20:08
Comonad for protected operations
> {-# LANGUAGE QuasiQuotes #-}
> {-# LANGUAGE EmptyDataDecls #-}
> import Control.Comonad
> import Language.Haskell.Codo
> data Input a
> data Output a