git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1167 from purescript/1166
39347bfPhil Freeman
examples/passing/Do.purs+2−2
@@ -16,8 +16,8 @@ instance applicativeMaybe :: Applicative Maybe where
16 pure = Just
16 pure = Just
17
17
18instance bindMaybe :: Bind Maybe where
18instance bindMaybe :: Bind Maybe where
19− (>>=) Nothing _ = Nothing
19+ bind Nothing _ = Nothing
20− (>>=) (Just a) f = f a
20+ bind (Just a) f = f a
21
21
22instance monadMaybe :: Prelude.Monad Maybe
22instance monadMaybe :: Prelude.Monad Maybe
23
23
examples/passing/MonadState.purs+1−1
@@ -22,7 +22,7 @@ instance applicativeState :: Applicative (State s) where
22 pure a = State $ \s -> Tuple s a
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+ bind 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
28instance monadState :: Monad (State s)
28instance monadState :: Monad (State s)
examples/passing/NewtypeEff.purs+1−1
@@ -19,7 +19,7 @@ instance applicativeT :: Applicative T where
19 pure t = T (pure t)
19 pure t = T (pure t)
20
20
21instance bindT :: Bind T where
21instance bindT :: Bind T where
22− (>>=) (T t) f = T (t >>= \x -> runT (f x))
22+ bind (T t) f = T (t >>= \x -> runT (f x))
23
23
24instance monadT :: Monad T
24instance monadT :: Monad T
25
25
examples/passing/RebindableSyntax.purs+2−2
@@ -9,7 +9,7 @@ example1 = do
9 " for"
9 " for"
10 " Semigroup"
10 " Semigroup"
11 where
11 where
12− (>>=) x f = x <> f unit
12+ bind x f = x <> f unit
13
13
14(*>) :: forall f a b. (Apply f) => f a -> f b -> f b
14(*>) :: forall f a b. (Apply f) => f a -> f b -> f b
15(*>) fa fb = const id <$> fa <*> fb
15(*>) fa fb = const id <$> fa <*> fb
@@ -32,7 +32,7 @@ example2 = do
32 Const " for"
32 Const " for"
33 Const " Apply"
33 Const " Apply"
34 where
34 where
35− (>>=) x f = x *> f unit
35+ bind x f = x *> f unit
36
36
37main = do
37main = do
38 Debug.Trace.trace example1
38 Debug.Trace.trace example1
examples/passing/Superclasses3.purs+1−1
@@ -31,7 +31,7 @@ instance applicativeMTrace :: Applicative MTrace where
31 pure = MTrace <<< 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+ bind m f = MTrace (runMTrace m >>= (runMTrace <<< f))
35
35
36instance monadMTrace :: Monad MTrace
36instance monadMTrace :: Monad MTrace
37
37
examples/passing/TypeClasses.purs+3−3
@@ -31,7 +31,7 @@ instance applicativeData :: Applicative Data where
31 pure = Data
31 pure = Data
32
32
33instance bindData :: Bind Data where
33instance bindData :: Bind Data where
34− (>>=) (Data a) f = f a
34+ bind (Data a) f = f a
35
35
36instance monadData :: Monad Data
36instance monadData :: Monad Data
37
37
@@ -47,8 +47,8 @@ instance applicativeMaybe :: Applicative Maybe where
47 pure = Just
47 pure = Just
48
48
49instance bindMaybe :: Bind Maybe where
49instance bindMaybe :: Bind Maybe where
50− (>>=) Nothing _ = Nothing
50+ bind Nothing _ = Nothing
51− (>>=) (Just a) f = f a
51+ bind (Just a) f = f a
52
52
53instance monadMaybe :: Monad Maybe
53instance monadMaybe :: Monad Maybe
54
54
src/Language/PureScript/CodeGen/JS/Optimizer/MagicDo.hs+2−2
@@ -81,8 +81,8 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
81 isPure (JSApp purePoly [effDict]) | isPurePoly purePoly && isEffDict C.applicativeEffDictionary effDict = True
81 isPure (JSApp purePoly [effDict]) | isPurePoly purePoly && isEffDict C.applicativeEffDictionary effDict = True
82 isPure _ = False
82 isPure _ = False
83 -- Check if an expression represents the polymorphic >>= function
83 -- Check if an expression represents the polymorphic >>= function
84− isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && prop == identToJs (Op (C.>>=))
84+ isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && (prop `elem` map identToJs [Ident C.bind, Op (C.>>=)])
85− isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && bind == (C.>>=)
85+ isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && (bind `elem` [C.bind, (C.>>=)])
86 isBindPoly _ = False
86 isBindPoly _ = False
87 -- Check if an expression represents the polymorphic return function
87 -- Check if an expression represents the polymorphic return function
88 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
88 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
src/Language/PureScript/Constants.hs+3
@@ -71,6 +71,9 @@ module Language.PureScript.Constants where
71(||) :: String
71(||) :: String
72(||) = "||"
72(||) = "||"
73
73
74+bind :: String
75+bind = "bind"
76+
74unsafeIndex :: String
77unsafeIndex :: String
75unsafeIndex = "unsafeIndex"
78unsafeIndex = "unsafeIndex"
76
79
src/Language/PureScript/Sugar/DoNotation.hs+3−3
@@ -10,7 +10,7 @@
10--
10--
11-- |
11-- |
12-- This module implements the desugaring pass which replaces do-notation statements with
12-- This module implements the desugaring pass which replaces do-notation statements with
13−-- appropriate calls to (>>=) from the Prelude.Monad type class.
13+-- appropriate calls to bind from the Prelude.Monad type class.
14--
14--
15-----------------------------------------------------------------------------
15-----------------------------------------------------------------------------
16
16
@@ -32,7 +32,7 @@ import Control.Monad.Error.Class (MonadError(..))
32import Control.Monad.Supply.Class
32import Control.Monad.Supply.Class
33
33
34-- |
34-- |
35−-- Replace all @DoNotationBind@ and @DoNotationValue@ constructors with applications of the Prelude.(>>=) function,
35+-- Replace all @DoNotationBind@ and @DoNotationValue@ constructors with applications of the Prelude.bind function,
36-- and all @DoNotationLet@ constructors with let expressions.
36-- and all @DoNotationLet@ constructors with let expressions.
37--
37--
38desugarDoModule :: forall m. (Applicative m, MonadSupply m, MonadError MultipleErrors m) => Module -> m Module
38desugarDoModule :: forall m. (Applicative m, MonadSupply m, MonadError MultipleErrors m) => Module -> m Module
@@ -45,7 +45,7 @@ desugarDo d =
45 in f d
45 in f d
46 where
46 where
47 bind :: Expr
47 bind :: Expr
48− bind = Var (Qualified Nothing (Op (C.>>=)))
48+ bind = Var (Qualified Nothing (Ident (C.bind)))
49
49
50 replace :: Expr -> m Expr
50 replace :: Expr -> m Expr
51 replace (Do els) = go els
51 replace (Do els) = go els
tests/prelude/Prelude.purs+7−4
@@ -17,7 +17,7 @@ module Prelude
17 , Functor, (<$>), (<#>), void
17 , Functor, (<$>), (<#>), void
18 , Apply, (<*>)
18 , Apply, (<*>)
19 , Applicative, pure, liftA1
19 , Applicative, pure, liftA1
20− , Bind, (>>=)
20+ , Bind, bind, (>>=)
21 , Monad, return, liftM1, ap
21 , Monad, return, liftM1, ap
22 , Semigroup, (<>), (++)
22 , Semigroup, (<>), (++)
23 , Semiring, (+), zero, (*), one
23 , Semiring, (+), zero, (*), one
@@ -127,12 +127,15 @@ module Prelude
127 liftA1 f a = pure f <*> a
127 liftA1 f a = pure f <*> a
128
128
129 infixl 1 >>=
129 infixl 1 >>=
130+
131+ (>>=) :: forall m a b. (Bind m) => m a -> (a -> m b) -> m b
132+ (>>=) = bind
130
133
131 class (Apply m) <= Bind m where
134 class (Apply m) <= Bind m where
132− (>>=) :: forall a b. m a -> (a -> m b) -> m b
135+ bind :: forall a b. m a -> (a -> m b) -> m b
133
136
134 instance bindArr :: Bind ((->) r) where
137 instance bindArr :: Bind ((->) r) where
135− (>>=) m f x = f (m x) x
138+ bind m f x = f (m x) x
136
139
137 class (Applicative m, Bind m) <= Monad m
140 class (Applicative m, Bind m) <= Monad m
138
141
@@ -585,7 +588,7 @@ module Control.Monad.Eff
585 pure = returnE
588 pure = returnE
586
589
587 instance bindEff :: Bind (Eff e) where
590 instance bindEff :: Bind (Eff e) where
588− (>>=) = bindE
591+ bind = bindE
589
592
590 instance monadEff :: Monad (Eff e)
593 instance monadEff :: Monad (Eff e)
591
594