git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix 1166, Use bind instead of >>= in do desugaring
764ba6ePhil Freeman
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