git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Inserted Bind into hierarchy.
commit77833023d9e2cbebbc9e3f2f7d326099611eb234 authorjoneshf <jones3.hardy@gmail.com> dateSun 6 Apr 2014, 20:38 (13 years ago) parente0526d3
5 files changed+30−14
examples/passing/Do.purs+4−2 examples/passing/MonadState.purs+4−2 examples/passing/Superclasses3.purs+3−1 examples/passing/TypeClasses.purs+12−6 prelude/prelude.purs+7−3
examples/passing/Do.purs+4−2
@@ -15,11 +15,13 @@ instance applyMaybe :: Apply Maybe where
1515instance applicativeMaybe :: Applicative Maybe where
1616 pure = Just
1717
18−instance monadMaybe :: Prelude.Monad Maybe where
19− return = Just
18+instance bindMaybe :: Bind Maybe where
2019 (>>=) Nothing _ = Nothing
2120 (>>=) (Just a) f = f a
2221
22+instance monadMaybe :: Prelude.Monad Maybe where
23+ return = Just
24+
2325test1 = \_ -> do
2426 Just "abc"
2527
examples/passing/MonadState.purs+4−2
@@ -21,11 +21,13 @@ instance applyState :: Apply (State s) where
2121instance applicativeState :: Applicative (State s) where
2222 pure = return
2323
24−instance monadState :: Prelude.Monad (State s) where
25− return a = State $ \s -> Tuple s a
24+instance bindState :: Bind (State s) where
2625 (>>=) f g = State $ \s -> case runState s f of
2726 Tuple s1 a -> runState s1 (g a)
2827
28+instance monadState :: Monad (State s) where
29+ return a = State $ \s -> Tuple s a
30+
2931instance monadStateState :: MonadState s (State s) where
3032 get = State (\s -> Tuple s s)
3133 put s = State (\_ -> Tuple s {})
examples/passing/Superclasses3.purs+3−1
@@ -30,9 +30,11 @@ instance applyMTrace :: Apply MTrace where
3030instance applicativeMTrace :: Applicative MTrace where
3131 pure = return
3232
33+instance bindMTrace :: Bind MTrace where
34+ (>>=) m f = MTrace (runMTrace m >>= (runMTrace <<< f))
35+
3336instance monadMTrace :: Monad MTrace where
3437 return = MTrace <<< return
35− (>>=) m f = MTrace (runMTrace m >>= (runMTrace <<< f))
3638
3739instance writerMTrace :: MonadWriter String MTrace where
3840 tell s = MTrace (trace s)
examples/passing/TypeClasses.purs+12−6
@@ -30,10 +30,12 @@ instance applyData :: Apply Data where
3030instance applicativeData :: Applicative Data where
3131 pure = return
3232
33−instance monadData :: Prelude.Monad Data where
34− return = Data
33+instance bindData :: Bind Data where
3534 (>>=) (Data a) f = f a
3635
36+instance monadData :: Monad Data where
37+ return = Data
38+
3739data Maybe a = Nothing | Just a
3840
3941instance functorMaybe :: Functor Maybe where
@@ -45,11 +47,13 @@ instance applyMaybe :: Apply Maybe where
4547instance applicativeMaybe :: Applicative Maybe where
4648 pure = return
4749
48−instance monadMaybe :: Prelude.Monad Maybe where
49− return = Just
50+instance bindMaybe :: Bind Maybe where
5051 (>>=) Nothing _ = Nothing
5152 (>>=) (Just a) f = f a
5253
54+instance monadMaybe :: Monad Maybe where
55+ return = Just
56+
5357test4 :: forall a m. (Monad m) => a -> m Number
5458test4 = \_ -> return 1
5559
@@ -70,10 +74,12 @@ instance applyFunction :: Apply ((->) r) where
7074instance applicativeFunction :: Applicative ((->) r) where
7175 pure = return
7276
73−instance monadFunction :: Prelude.Monad ((->) r) where
74− return a r = a
77+instance bindFunction :: Bind ((->) r) where
7578 (>>=) f g r = g (f r) r
7679
80+instance monadFunction :: Monad ((->) r) where
81+ return a r = a
82+
7783ask r = r
7884
7985runReader r f = f r
prelude/prelude.purs+7−3
@@ -76,10 +76,12 @@ module Prelude where
7676
7777 infixl 1 >>=
7878
79− class (Applicative m) <= Monad m where
80− return :: forall a. a -> m a
79+ class (Apply m) <= Bind m where
8180 (>>=) :: forall a b. m a -> (a -> m b) -> m b
8281
82+ class (Applicative m, Bind m) <= Monad m where
83+ return :: forall a. a -> m a
84+
8385 liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
8486 liftM1 f a = do
8587 a' <- a
@@ -398,9 +400,11 @@ module Control.Monad.Eff where
398400 instance applicativeEff :: Applicative (Eff e) where
399401 pure = return
400402
403+ instance bindEffInstance :: Bind (Eff e) where
404+ (>>=) = bindEff
405+
401406 instance monadEff :: Monad (Eff e) where
402407 return = retEff
403− (>>=) = bindEff
404408
405409 foreign import untilE "function untilE(f) {\
406410 \ return function() {\