Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt parsonsmatt/freeeeee.hs
Last active Nov 11, 2015

Embed
What would you like to do?
to free or not to free
-- 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
You can’t perform that action at this time.