Created
May 18, 2015 01:52
-
-
Save bohde/b56d7addc6464af5ac87 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
module Fork where | |
newtype Fork' f a = Fork' { runFork :: forall r. (a -> r) -> | |
(f r -> r) -> | |
(forall b. Fork' f b -> r -> r) -> r } deriving Functor | |
instance Applicative (Fork' f) where | |
pure a = Fork' (\kh _ _ -> kh a) | |
Fork' f <*> Fork' g = Fork' (\kh ka kf -> f (\a -> g (\b -> kh (a b)) ka kf) ka kf) | |
instance Monad (Fork' f) where | |
return = pure | |
Fork' m >>= f = Fork' (\kh ka kf -> m (\a -> runFork (f a) kh ka kf) ka kf) | |
liftF' :: Functor f => f a -> Fork' f a | |
liftF' f = Fork' (\kh ka _ -> ka (fmap kh f)) | |
fork' :: Functor f => Fork' f a -> Fork' f () | |
fork' f = Fork' (\kh _ kf -> kf f (kh ())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment