@@ -10,6 +10,7 @@ import Prelude.List
10import Prelude.Maybe
10import Prelude.Maybe
11import Prelude.Monad
11import Prelude.Monad
12import Prelude.Applicative
12import Prelude.Applicative
13+import Prelude.Functor
13import Prelude.Either
14import Prelude.Either
14import Prelude.Vect
15import Prelude.Vect
15import Prelude.Strings
16import Prelude.Strings
@@ -67,41 +68,11 @@ instance Show a => Show (Maybe a) where
67 show Nothing = "Nothing"
68 show Nothing = "Nothing"
68 show (Just x) = "Just " ++ show x
69 show (Just x) = "Just " ++ show x
72−instance Monad IO where
73− return t = io_return t
74− b >>= k = io_bind b k
76−instance Monad Maybe where
79− Nothing >>= k = Nothing
82−instance MonadPlus Maybe where
85− mplus (Just x) _ = Just x
86− mplus Nothing (Just y) = Just y
87− mplus Nothing Nothing = Nothing
89−instance Monad (Either e) where
92− (Left n) >>= _ = Left n
93− (Right r) >>= f = f r
95−instance Monad List where
97− m >>= f = concatMap f m
99−instance MonadPlus List where
103---- Functor instances
71---- Functor instances
73+instance Functor IO where
74+ fmap f io = io_bind io (io_return . f)
105instance Functor Maybe where
76instance Functor Maybe where
106 fmap f (Just x) = Just (f x)
77 fmap f (Just x) = Just (f x)
107 fmap f Nothing = Nothing
78 fmap f Nothing = Nothing
@@ -115,6 +86,11 @@ instance Functor List where
116---- Applicative instances
87---- Applicative instances
89+instance Applicative IO where
92+ am <$> bm = io_bind am (\f => io_bind bm (io_return . f))
118instance Applicative Maybe where
94instance Applicative Maybe where
119 pure = Just
95 pure = Just
@@ -133,6 +109,39 @@ instance Applicative List where
134 fs <$> vs = concatMap (\f => map f vs) fs
110 fs <$> vs = concatMap (\f => map f vs) fs
114+instance Monad IO where
115+ return t = io_return t
116+ b >>= k = io_bind b k
118+instance Monad Maybe where
121+ Nothing >>= k = Nothing
122+ (Just x) >>= k = k x
124+instance MonadPlus Maybe where
127+ mplus (Just x) _ = Just x
128+ mplus Nothing (Just y) = Just y
129+ mplus Nothing Nothing = Nothing
131+instance Monad (Either e) where
134+ (Left n) >>= _ = Left n
135+ (Right r) >>= f = f r
137+instance Monad List where
139+ m >>= f = concatMap f m
141+instance MonadPlus List where
136---- some mathematical operations
145---- some mathematical operations
138%include "math.h"
147%include "math.h"