Skip to content

Instantly share code, notes, and snippets.

@akhileshs
Created April 5, 2016 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhileshs/1d72bcfe7c96189968bcd38b9251c60b to your computer and use it in GitHub Desktop.
Save akhileshs/1d72bcfe7c96189968bcd38b9251c60b to your computer and use it in GitHub Desktop.
data Toy b next =
Output b next
| Bell next
| Done
deriving (Show)
data FixE f e = Fix (f (FixE f e)) | Throw e
catch :: (Functor f) => FixE f e1 -> (e1 -> FixE f e2) -> FixE f e2
catch (Fix x) f = Fix (fmap (flip catch f) x)
catch (Throw e) f = f e
instance (Functor f) => Monad (Free f) where
return = Pure
(Free x) >>= f = Free (fmap (>>= f) x)
(Pure r) >>= f = f r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment