@@ -8,6 +8,8 @@ import prelude.nat
8import prelude.fin
8import prelude.fin
9import prelude.list
9import prelude.list
10import prelude.maybe
10import prelude.maybe
12+import prelude.applicative
11import prelude.either
13import prelude.either
12import prelude.vect
14import prelude.vect
13import prelude.strings
15import prelude.strings
@@ -64,17 +66,7 @@ instance Show a => Show (Maybe a) where
64 show Nothing = "Nothing"
66 show Nothing = "Nothing"
65 show (Just x) = "Just " ++ show x
67 show (Just x) = "Just " ++ show x
67−---- Monad and instances
69+---- Monad instances
71−class Monad (m : Set -> Set) where
73− (>>=) : m a -> (a -> m b) -> m b
75−class Monad m => MonadPlus (m : Set -> Set) where
76− mplus : m a -> m a -> m a
79instance Monad IO where
71instance Monad IO where
80 return t = io_return t
72 return t = io_return t
@@ -101,14 +93,7 @@ instance MonadPlus List where
101 mzero = []
93 mzero = []
102 mplus = app
94 mplus = app
104−guard : MonadPlus m => Bool -> m ()
96+---- Functor instances
105−guard True = return ()
110−class Functor (f : Set -> Set) where
111− fmap : (a -> b) -> f a -> f b
113instance Functor Maybe where
98instance Functor Maybe where
114 fmap f (Just x) = Just (f x)
99 fmap f (Just x) = Just (f x)
@@ -117,13 +102,14 @@ instance Functor Maybe where
117instance Functor List where
102instance Functor List where
118 fmap = map
103 fmap = map
120−---- Applicative functors/Idioms
105+---- Applicative instances
107+instance Applicative Maybe where
122−infixl 2 <$>
110+ (Just f) <$> (Just a) = Just (f a)
111+ Nothing <$> Nothing = Nothing
124−class Functor f => Applicative (f : Set -> Set) where
126− (<$>) : f (a -> b) -> f a -> f b
128---- some mathematical operations
114---- some mathematical operations