Last active
June 23, 2016 14:10
-
-
Save jooyunghan/9ae293603f643584bc209be7d3454765 to your computer and use it in GitHub Desktop.
Monad instance of Fetch from ICFP2014 Haxl paper
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
instance Monad Fetch where | |
return a = Fetch $ \ref -> return (Done a) | |
Fetch m >>= k = Fetch $ \ref -> do | |
r <- m ref | |
case r of | |
Done a -> unFetch (k a) ref | |
Blocked br c -> return (Blocked br (c >>= k)) | |
Throw e -> return (Throw e) |
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
instance Monad (GenHaxl u) where | |
return a = GenHaxl $ \_env _ref -> return (Done a) | |
GenHaxl m >>= k = GenHaxl $ \env ref -> do | |
e <- m env ref | |
case e of | |
Done a -> unHaxl (k a) env ref | |
Throw e -> return (Throw e) | |
Blocked cont -> return (Blocked (cont :>>= k)) | |
fail msg = GenHaxl $ \_env _ref -> | |
return $ Throw $ toException $ MonadFail $ Text.pack msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment