on master help sign in
Merge pull request #319 from david-christiansen/remove-return

Remove "return" from Monad

commitb62a2e4245414a79e07827b8c0fab9d0eafc6db3 authorEdwin Brady <edwin.brady@gmail.com> dateFri 7 Jun 2013, 05:27 (13 years ago) parent3c58071d0460a3
8 files changed+3−15
lib/Control/IOExcept.idr−1 lib/Control/Monad/Identity.idr−1 lib/Control/Monad/State.idr−2 lib/Data/Morphisms.idr−1 lib/Network/Cgi.idr−2 lib/Prelude.idr−6 lib/Prelude/Monad.idr+3−1 lib/System/Concurrency/Process.idr−1
lib/Control/IOExcept.idr−1
@@ -16,7 +16,6 @@ instance Applicative (IOExcept e) where
1616 return (f' <$> a'))
1717
1818instance Monad (IOExcept e) where
19− return = pure
2019 (ioM x) >>= k = ioM (do x' <- x;
2120 case x' of
2221 Right a => let (ioM ka) = k a in
lib/Control/Monad/Identity.idr−1
@@ -16,5 +16,4 @@ instance Applicative Identity where
1616 (Id f) <$> (Id g) = Id (f g)
1717
1818instance Monad Identity where
19− return x = Id x
2019 (Id x) >>= k = k x
lib/Control/Monad/State.idr−2
@@ -27,8 +27,6 @@ instance Monad f => Applicative (StateT s f) where
2727 return (g b, t))
2828
2929instance Monad m => Monad (StateT s m) where
30− return x = ST (\st => return (x, st))
31−
3230 (ST f) >>= k = ST (\st => do (v, st') <- f st
3331 let ST kv = k v
3432 kv st')
lib/Data/Morphisms.idr−1
@@ -30,7 +30,6 @@ instance Applicative (Morphism r) where
3030 (Mor f) <$> (Mor a) = Mor $ \r => f r $ a r
3131
3232instance Monad (Morphism r) where
33− return a = Mor $ const a
3433 (Mor h) >>= f = Mor $ \r => applyMor (f $ h r) r
3534
3635instance Semigroup (Endomorphism a) where
lib/Network/Cgi.idr−2
@@ -41,8 +41,6 @@ instance Applicative CGI where
4141instance Monad CGI where {
4242 (>>=) (MkCGI f) k = MkCGI (\s => do v <- f s
4343 getAction (k (fst v)) (snd v))
44−
45− return v = MkCGI (\s => return (v, s))
4644}
4745
4846setInfo : CGIInfo -> CGI ()
lib/Prelude.idr−6
@@ -124,23 +124,17 @@ instance Alternative List where
124124---- Monad instances
125125
126126instance Monad IO where
127− return t = io_return t
128127 b >>= k = io_bind b k
129128
130129instance Monad Maybe where
131− return t = Just t
132−
133130 Nothing >>= k = Nothing
134131 (Just x) >>= k = k x
135132
136133instance Monad (Either e) where
137− return = Right
138−
139134 (Left n) >>= _ = Left n
140135 (Right r) >>= f = f r
141136
142137instance Monad List where
143− return x = [x]
144138 m >>= f = concatMap f m
145139
146140---- some mathematical operations
lib/Prelude/Monad.idr+3−1
@@ -11,8 +11,10 @@ import Prelude.Applicative
1111infixl 5 >>=
1212
1313class Applicative m => Monad (m : Type -> Type) where
14− return : a -> m a
1514 (>>=) : m a -> (a -> m b) -> m b
1615
1716flatten : Monad m => m (m a) -> m a
1817flatten a = a >>= id
18+
19+return : Monad m => a -> m a
20+return = pure
lib/System/Concurrency/Process.idr−1
@@ -23,7 +23,6 @@ instance Applicative (Process msg) where
2323 (lift f) <$> (lift a) = lift (f <$> a)
2424
2525instance Monad (Process msg) where
26− return = lift . return
2726 (lift io) >>= k = lift (do x <- io
2827 case k x of
2928 lift v => v)