Created
April 22, 2021 22:41
-
-
Save shhyou/d4376e3829e37ac73e53c1264a98635a to your computer and use it in GitHub Desktop.
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
import Control.Applicative | |
import Control.Monad | |
main = putStrLn "Hello, World!" | |
data Void | |
data Cont r a = Cont ((a -> r) -> r) | |
unCont (Cont m) = m | |
instance Functor (Cont r) where | |
fmap f (Cont ma) = Cont (\k -> ma (\a -> k (f a))) | |
instance Applicative (Cont r) where | |
pure a = Cont (\k -> k a) | |
(Cont mf) <*> (Cont ma) = Cont (\k -> mf (\f -> ma (\a -> k (f a)))) | |
instance Monad (Cont r) where | |
(Cont ma) >>= amb = Cont (\k -> ma (\a -> unCont (amb a) k)) | |
exc0 :: Cont r (Either a (a -> r)) | |
exc0 = Cont (\k -> k (Right (\a -> k (Left a)))) | |
exc :: Cont r (Either a (a -> Cont r b)) | |
exc = Cont (\k -> k (Right (\a -> Cont (\k' -> k (Left a))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment