git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use Supply to generate arg name for swap lambda
commit9f5eeeb557064409a02260616591d134403d4a9c authorGary Burgess <gary.burgess@gmail.com> dateSat 7 Feb 2015, 23:41 (12 years ago) parent99cd098
2 files changed+14−11
src/Language/PureScript/Sugar.hs+2−2 src/Language/PureScript/Sugar/Operators.hs+12−9
src/Language/PureScript/Sugar.hs+2−2
@@ -58,8 +58,8 @@ import Language.PureScript.Sugar.TypeDeclarations as S
5858desugar :: [Module] -> SupplyT (Either ErrorStack) [Module]
5959desugar = map removeSignedLiterals
6060 >>> map desugarObjectConstructors
61− >>> map desugarOperatorSections
62− >>> mapM desugarDoModule
61+ >>> mapM desugarOperatorSections
62+ >=> mapM desugarDoModule
6363 >=> desugarCasesModule
6464 >=> lift . (desugarTypeDeclarationsModule
6565 >=> desugarImports
src/Language/PureScript/Sugar/Operators.hs+12−9
@@ -25,9 +25,10 @@ module Language.PureScript.Sugar.Operators (
2525 desugarOperatorSections
2626) where
2727
28−import Language.PureScript.Names
2928import Language.PureScript.AST
3029import Language.PureScript.Errors
30+import Language.PureScript.Names
31+import Language.PureScript.Supply
3132
3233import Control.Applicative
3334import Control.Monad.State
@@ -149,14 +150,16 @@ matchOp op = do
149150 ident <- parseOp
150151 guard $ ident == op
151152
152−desugarOperatorSections :: Module -> Module
153−desugarOperatorSections (Module mn ds exts) = Module mn (map goDecl ds) exts
153+desugarOperatorSections :: Module -> SupplyT (Either ErrorStack) Module
154+desugarOperatorSections (Module mn ds exts) = Module mn <$> mapM goDecl ds <*> pure exts
154155 where
155156
156− goDecl :: Declaration -> Declaration
157− (goDecl, _, _) = everywhereOnValues id goExpr id
157+ goDecl :: Declaration -> SupplyT (Either ErrorStack) Declaration
158+ (goDecl, _, _) = everywhereOnValuesM return goExpr return
158159
159− goExpr :: Expr -> Expr
160− goExpr (OperatorSection op (Left val)) = App (Var op) val
161− goExpr (OperatorSection op (Right val)) = Abs (Left $ Ident "_lhs") $ App (App (Var op) (Var (Qualified Nothing (Ident "_lhs")))) val
162− goExpr other = other
160+ goExpr :: Expr -> SupplyT (Either ErrorStack) Expr
161+ goExpr (OperatorSection op (Left val)) = return $ App (Var op) val
162+ goExpr (OperatorSection op (Right val)) = do
163+ arg <- Ident <$> freshName
164+ return $ Abs (Left arg) $ App (App (Var op) (Var (Qualified Nothing arg))) val
165+ goExpr other = return other