@@ -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