git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Move out of Monad type class.
commitd4efd8879cfea729bec90965fec2faab4574a3cc authorPhil Freeman <paf31@cantab.net> dateTue 8 Apr 2014, 12:49 (13 years ago) parent47cf7b6
5 files changed+16−21
examples/passing/Do.purs+1−2 examples/passing/MonadState.purs+2−3 examples/passing/Superclasses3.purs+2−3 examples/passing/TypeClasses.purs+6−9 prelude/prelude.purs+5−4
examples/passing/Do.purs+1−2
@@ -19,8 +19,7 @@ instance bindMaybe :: Bind Maybe where
1919 (>>=) Nothing _ = Nothing
2020 (>>=) (Just a) f = f a
2121
22−instance monadMaybe :: Prelude.Monad Maybe where
23− return = Just
22+instance monadMaybe :: Prelude.Monad Maybe
2423
2524test1 = \_ -> do
2625 Just "abc"
examples/passing/MonadState.purs+2−3
@@ -19,14 +19,13 @@ instance applyState :: Apply (State s) where
1919 (<*>) = ap
2020
2121instance applicativeState :: Applicative (State s) where
22− pure = return
22+ pure a = State $ \s -> Tuple s a
2323
2424instance bindState :: Bind (State s) where
2525 (>>=) f g = State $ \s -> case runState s f of
2626 Tuple s1 a -> runState s1 (g a)
2727
28−instance monadState :: Monad (State s) where
29− return a = State $ \s -> Tuple s a
28+instance monadState :: Monad (State s)
3029
3130instance monadStateState :: MonadState s (State s) where
3231 get = State (\s -> Tuple s s)
examples/passing/Superclasses3.purs+2−3
@@ -28,13 +28,12 @@ instance applyMTrace :: Apply MTrace where
2828 (<*>) = ap
2929
3030instance applicativeMTrace :: Applicative MTrace where
31− pure = return
31+ pure = MTrace <<< return
3232
3333instance bindMTrace :: Bind MTrace where
3434 (>>=) m f = MTrace (runMTrace m >>= (runMTrace <<< f))
3535
36−instance monadMTrace :: Monad MTrace where
37− return = MTrace <<< return
36+instance monadMTrace :: Monad MTrace
3837
3938instance writerMTrace :: MonadWriter String MTrace where
4039 tell s = MTrace (trace s)
examples/passing/TypeClasses.purs+6−9
@@ -28,13 +28,12 @@ instance applyData :: Apply Data where
2828 (<*>) = ap
2929
3030instance applicativeData :: Applicative Data where
31− pure = return
31+ pure = Data
3232
3333instance bindData :: Bind Data where
3434 (>>=) (Data a) f = f a
3535
36−instance monadData :: Monad Data where
37− return = Data
36+instance monadData :: Monad Data
3837
3938data Maybe a = Nothing | Just a
4039
@@ -45,14 +44,13 @@ instance applyMaybe :: Apply Maybe where
4544 (<*>) = ap
4645
4746instance applicativeMaybe :: Applicative Maybe where
48− pure = return
47+ pure = Just
4948
5049instance bindMaybe :: Bind Maybe where
5150 (>>=) Nothing _ = Nothing
5251 (>>=) (Just a) f = f a
5352
54−instance monadMaybe :: Monad Maybe where
55− return = Just
53+instance monadMaybe :: Monad Maybe
5654
5755test4 :: forall a m. (Monad m) => a -> m Number
5856test4 = \_ -> return 1
@@ -72,13 +70,12 @@ instance applyFunction :: Apply ((->) r) where
7270 (<*>) = ap
7371
7472instance applicativeFunction :: Applicative ((->) r) where
75− pure = return
73+ pure a _ = a
7674
7775instance bindFunction :: Bind ((->) r) where
7876 (>>=) f g r = g (f r) r
7977
80−instance monadFunction :: Monad ((->) r) where
81− return a r = a
78+instance monadFunction :: Monad ((->) r)
8279
8380ask r = r
8481
prelude/prelude.purs+5−4
@@ -79,8 +79,10 @@ module Prelude where
7979 class (Apply m) <= Bind m where
8080 (>>=) :: forall a b. m a -> (a -> m b) -> m b
8181
82− class (Applicative m, Bind m) <= Monad m where
83− return :: forall a. a -> m a
82+ class (Applicative m, Bind m) <= Monad m
83+
84+ return :: forall m a. (Monad m) => a -> m a
85+ return = pure
8486
8587 liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
8688 liftM1 f a = do
@@ -403,8 +405,7 @@ module Control.Monad.Eff where
403405 instance bindEff :: Bind (Eff e) where
404406 (>>=) = bindE
405407
406− instance monadEff :: Monad (Eff e) where
407− return = returnE
408+ instance monadEff :: Monad (Eff e)
408409
409410 foreign import untilE "function untilE(f) {\
410411 \ return function() {\