Created
March 9, 2014 17:30
-
-
Save puffnfresh/9451242 to your computer and use it in GitHub Desktop.
Transforming an operational GADT using the Yoneda lemma.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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