Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created March 9, 2014 17:30
Show Gist options
  • Save puffnfresh/9451242 to your computer and use it in GitHub Desktop.
Save puffnfresh/9451242 to your computer and use it in GitHub Desktop.
Transforming an operational GADT using the Yoneda lemma.
{-# LANGUAGE GADTs #-}
-- The "operational" form
data Action a where
Print :: String -> Action ()
Read :: Action String
{-
Yoneda lemma says these two are isomorphic:
f a
forall b. (a -> b) -> f b
Let's apply that to the result type of each data constructor in the GADT.
-}
-- The "free" form
data Action' a = Print' String (() -> a)
| Read' (String -> a)
{-
Exercise: can we now simplify the Print' constructor?
Exercise: can we provide an isomorphism using Control.Functor.Yoneda?
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment