@@ -20,7 +20,8 @@
2020{-# LANGUAGE Rank2Types, FlexibleContexts #-}
2121
2222module Language.PureScript.Sugar.Operators (
23− rebracket
23+ rebracket,
24+ removeSignedLiterals
2425) where
2526
2627import Language.PureScript.Names
@@ -42,6 +43,8 @@ import qualified Text.Parsec as P
4243import qualified Text.Parsec.Pos as P
4344import qualified Text.Parsec.Expr as P
4445
46+import qualified Language.PureScript.Constants as C
47+
4548-- |
4649-- Remove explicit parentheses and reorder binary operator applications
4750--
@@ -52,6 +55,14 @@ rebracket ms = do
5255 let opTable = customOperatorTable fixities
5356 mapM (rebracketModule opTable) ms
5457
58+removeSignedLiterals :: (D.Data d) => d -> d
59+removeSignedLiterals = G.everywhere (G.mkT go)
60+ where
61+ go (UnaryMinus (NumericLiteral (Left n))) = NumericLiteral (Left $ negate n)
62+ go (UnaryMinus (NumericLiteral (Right n))) = NumericLiteral (Right $ negate n)
63+ go (UnaryMinus val) = App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.negate))) val
64+ go other = other
65+
5566rebracketModule :: [[(Qualified Ident, Value -> Value -> Value, Associativity)]] -> Module -> Either String Module
5667rebracketModule opTable (Module mn ds exts) = Module mn <$> (removeParens <$> G.everywhereM' (G.mkM (matchOperators opTable)) ds) <*> pure exts
5768