Haskell : Monad Lifters

liftM’ :: Monad m => (a->r)->m a -> m r
liftM’ f m = m >>= \a-> return (f a)

liftM2′ :: Monad m => (a->b->r)->m a -> m b -> m r
liftM2′ f m1 m2 = liftM’ f m1 >>= \f1 ->
m2 >>= \a1 -> return (f1 a1)

liftM3′ :: Monad m => (a->b->c->r) -> m a -> m b -> m c -> m r
liftM3′ f m1 m2 m3 = liftM2′ f m1 m2 >>= \f1 ->
m3 >>= \a1 -> return (f1 a1)

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s