@@ -8,6 +8,8 @@ import prelude.nat
88import prelude.fin
99import prelude.list
1010import prelude.maybe
11+import prelude.monad
12+import prelude.applicative
1113import prelude.either
1214import prelude.vect
1315import prelude.strings
@@ -64,17 +66,7 @@ instance Show a => Show (Maybe a) where
6466 show Nothing = "Nothing"
6567 show (Just x) = "Just " ++ show x
6668
67−---- Monad and instances
68−
69−infixl 5 >>=
70−
71−class Monad (m : Set -> Set) where
72− return : a -> m a
73− (>>=) : m a -> (a -> m b) -> m b
74−
75−class Monad m => MonadPlus (m : Set -> Set) where
76− mplus : m a -> m a -> m a
77− mzero : m a
69+---- Monad instances
7870
7971instance Monad IO where
8072 return t = io_return t
@@ -101,14 +93,7 @@ instance MonadPlus List where
10193 mzero = []
10294 mplus = app
10395
104−guard : MonadPlus m => Bool -> m ()
105−guard True = return ()
106−guard False = mzero
107−
108−---- Functors
109−
110−class Functor (f : Set -> Set) where
111− fmap : (a -> b) -> f a -> f b
96+---- Functor instances
11297
11398instance Functor Maybe where
11499 fmap f (Just x) = Just (f x)
@@ -117,13 +102,14 @@ instance Functor Maybe where
117102instance Functor List where
118103 fmap = map
119104
120−---- Applicative functors/Idioms
105+---- Applicative instances
106+
107+instance Applicative Maybe where
108+ pure = Just
121109
122−infixl 2 <$>
110+ (Just f) <$> (Just a) = Just (f a)
111+ Nothing <$> Nothing = Nothing
123112
124−class Functor f => Applicative (f : Set -> Set) where
125− pure : a -> f a
126− (<$>) : f (a -> b) -> f a -> f b
127113
128114---- some mathematical operations
129115