Created
February 12, 2014 15:14
-
-
Save qnikst/8957284 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
{-# LANGUAGE Rank2Types #-} | |
import Data.Function | |
import Control.Monad | |
data M m a = M a | |
instance Monad (M m) where | |
return = M | |
(M a) >>= f = f a | |
runZ :: (forall m . M m a) -> a | |
runZ (M z) = z | |
data T a b = T {unT :: b} | |
foo :: Int -> M z (T z Int) | |
foo i = M (T i) | |
bar :: T z Int -> T z Int -> M z Int | |
bar = (return .). (+) `on` unT | |
-- λ> runZ $ join $ liftM2 (bar) (foo 1) (foo 2) | |
-- 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment