Created
April 5, 2016 19:55
-
-
Save akhileshs/1d72bcfe7c96189968bcd38b9251c60b to your computer and use it in GitHub Desktop.
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
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