Skip to content

Commit 394db07

Browse files
committed
hw5: monads, some problems
1 parent 22cedc3 commit 394db07

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ITMOPrelude/Monads.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{-# LANGUAGE NoImplicitPrelude, FlexibleInstances, UndecidableInstances #-}
2+
module ITMOPrelude.Monads where
3+
4+
import ITMOPrelude.Category
5+
6+
id x = x
7+
8+
class MonadFish m where
9+
returnFish :: a -> m a
10+
(>=>) :: (a -> m b) -> (b -> m c) -> a -> m c
11+
12+
instance Monad m => Functor m where
13+
fmap f x = x >>= f
14+
15+
class Functor m => MonadJoin m where
16+
returnJoin :: a -> m a
17+
join :: m (m a) -> m a
18+
19+
instance Monad m => MonadFish m where
20+
returnFish = return
21+
f >=> g = \a -> f a >>= \b -> g b
22+
23+
instance MonadFish m => Monad m where
24+
return = returnFish
25+
ma >>= f = id >=> f ma
26+
27+
instance MonadJoin m => Monad m where
28+
return = returnJoin
29+
f >>= g = join (fmap g f)

0 commit comments

Comments
 (0)