git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Move out of Monad type class.
d4efd88Phil Freeman
examples/passing/Do.purs+1−2
@@ -19,8 +19,7 @@ instance bindMaybe :: Bind Maybe where
19 (>>=) Nothing _ = Nothing
19 (>>=) Nothing _ = Nothing
20 (>>=) (Just a) f = f a
20 (>>=) (Just a) f = f a
21
21
22−instance monadMaybe :: Prelude.Monad Maybe where
22+instance monadMaybe :: Prelude.Monad Maybe
23− return = Just
24
23
25test1 = \_ -> do
24test1 = \_ -> do
26 Just "abc"
25 Just "abc"
examples/passing/MonadState.purs+2−3
@@ -19,14 +19,13 @@ instance applyState :: Apply (State s) where
19 (<*>) = ap
19 (<*>) = ap
20
20
21instance applicativeState :: Applicative (State s) where
21instance applicativeState :: Applicative (State s) where
22− pure = return
22+ pure a = State $ \s -> Tuple s a
23
23
24instance bindState :: Bind (State s) where
24instance bindState :: Bind (State s) where
25 (>>=) f g = State $ \s -> case runState s f of
25 (>>=) f g = State $ \s -> case runState s f of
26 Tuple s1 a -> runState s1 (g a)
26 Tuple s1 a -> runState s1 (g a)
27
27
28−instance monadState :: Monad (State s) where
28+instance monadState :: Monad (State s)
29− return a = State $ \s -> Tuple s a
30
29
31instance monadStateState :: MonadState s (State s) where
30instance monadStateState :: MonadState s (State s) where
32 get = State (\s -> Tuple s s)
31 get = State (\s -> Tuple s s)
examples/passing/Superclasses3.purs+2−3
@@ -28,13 +28,12 @@ instance applyMTrace :: Apply MTrace where
28 (<*>) = ap
28 (<*>) = ap
29
29
30instance applicativeMTrace :: Applicative MTrace where
30instance applicativeMTrace :: Applicative MTrace where
31− pure = return
31+ pure = MTrace <<< return
32
32
33instance bindMTrace :: Bind MTrace where
33instance bindMTrace :: Bind MTrace where
34 (>>=) m f = MTrace (runMTrace m >>= (runMTrace <<< f))
34 (>>=) m f = MTrace (runMTrace m >>= (runMTrace <<< f))
35
35
36−instance monadMTrace :: Monad MTrace where
36+instance monadMTrace :: Monad MTrace
37− return = MTrace <<< return
38
37
39instance writerMTrace :: MonadWriter String MTrace where
38instance writerMTrace :: MonadWriter String MTrace where
40 tell s = MTrace (trace s)
39 tell s = MTrace (trace s)
examples/passing/TypeClasses.purs+6−9
@@ -28,13 +28,12 @@ instance applyData :: Apply Data where
28 (<*>) = ap
28 (<*>) = ap
29
29
30instance applicativeData :: Applicative Data where
30instance applicativeData :: Applicative Data where
31− pure = return
31+ pure = Data
32
32
33instance bindData :: Bind Data where
33instance bindData :: Bind Data where
34 (>>=) (Data a) f = f a
34 (>>=) (Data a) f = f a
35
35
36−instance monadData :: Monad Data where
36+instance monadData :: Monad Data
37− return = Data
38
37
39data Maybe a = Nothing | Just a
38data Maybe a = Nothing | Just a
40
39
@@ -45,14 +44,13 @@ instance applyMaybe :: Apply Maybe where
45 (<*>) = ap
44 (<*>) = ap
46
45
47instance applicativeMaybe :: Applicative Maybe where
46instance applicativeMaybe :: Applicative Maybe where
48− pure = return
47+ pure = Just
49
48
50instance bindMaybe :: Bind Maybe where
49instance bindMaybe :: Bind Maybe where
51 (>>=) Nothing _ = Nothing
50 (>>=) Nothing _ = Nothing
52 (>>=) (Just a) f = f a
51 (>>=) (Just a) f = f a
53
52
54−instance monadMaybe :: Monad Maybe where
53+instance monadMaybe :: Monad Maybe
55− return = Just
56
54
57test4 :: forall a m. (Monad m) => a -> m Number
55test4 :: forall a m. (Monad m) => a -> m Number
58test4 = \_ -> return 1
56test4 = \_ -> return 1
@@ -72,13 +70,12 @@ instance applyFunction :: Apply ((->) r) where
72 (<*>) = ap
70 (<*>) = ap
73
71
74instance applicativeFunction :: Applicative ((->) r) where
72instance applicativeFunction :: Applicative ((->) r) where
75− pure = return
73+ pure a _ = a
76
74
77instance bindFunction :: Bind ((->) r) where
75instance bindFunction :: Bind ((->) r) where
78 (>>=) f g r = g (f r) r
76 (>>=) f g r = g (f r) r
79
77
80−instance monadFunction :: Monad ((->) r) where
78+instance monadFunction :: Monad ((->) r)
81− return a r = a
82
79
83ask r = r
80ask r = r
84
81
prelude/prelude.purs+5−4
@@ -79,8 +79,10 @@ module Prelude where
79 class (Apply m) <= Bind m where
79 class (Apply m) <= Bind m where
80 (>>=) :: forall a b. m a -> (a -> m b) -> m b
80 (>>=) :: forall a b. m a -> (a -> m b) -> m b
81
81
82− class (Applicative m, Bind m) <= Monad m where
82+ class (Applicative m, Bind m) <= Monad m
83+
83− return :: forall a. a -> m a
84+ return :: forall m a. (Monad m) => a -> m a
85+ return = pure
84
86
85 liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
87 liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
86 liftM1 f a = do
88 liftM1 f a = do
@@ -403,8 +405,7 @@ module Control.Monad.Eff where
403 instance bindEff :: Bind (Eff e) where
405 instance bindEff :: Bind (Eff e) where
404 (>>=) = bindE
406 (>>=) = bindE
405
407
406− instance monadEff :: Monad (Eff e) where
408+ instance monadEff :: Monad (Eff e)
407− return = returnE
408
409
409 foreign import untilE "function untilE(f) {\
410 foreign import untilE "function untilE(f) {\
410 \ return function() {\
411 \ return function() {\