Last active
November 11, 2015 02:23
-
-
Save parsonsmatt/1a58af69792c48d2b308 to your computer and use it in GitHub Desktop.
to free or not to free
This file contains 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
-- so I can either have a convention on returning a bare bool value | |
-- out of this strangeness. | |
data AndF k = forall f. (AndF :<: f) => And (Free f Bool) (Free f Bool) (Bool -> k) | |
testProgram :: (AndF :<: f) => Free f Bool | |
testProgram = do | |
asdf <- true .&& false | |
hmmm <- false .&& true | |
wat <- pure asdf .&& pure hmmm | |
return asdf | |
-- or, alternatively, I can return a value in the expression language, | |
-- which makes it easier to use the thing but complicates the type signatures | |
-- (and how do I get it out I guess??) | |
data AndF k = forall f. (AndF :<: f) => And (Free f Bool) (Free f Bool) (Free f Bool -> k) | |
testProgram :: (AndF :<: f) => Free f (Free f Bool) | |
testProgram = do | |
asdf <- true .&& false | |
hmmm <- false .&& true | |
wat <- asdf .&& hmmm | |
return asdf | |
-- boilerplate stuff: | |
instance Functor AndF where | |
fmap f (And a b k) = And a b (f . k) | |
(.&&) :: (AndF :<: f) => Free f Bool -> Free f Bool -> Free f Bool | |
a .&& b = Free . inj $ And a b Pure | |
true :: Functor f => Free f Bool | |
true = Pure True | |
false :: Functor f => Free f Bool | |
false = Pure False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment