git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #811 from philopon/fix/#807
4d2c9cfPhil Freeman
examples/passing/Operators.purs+12
@@ -64,6 +64,15 @@ module Main where
64 test16 :: Number -> Number -> Number
64 test16 :: Number -> Number -> Number
65 test16 x y = x .|. y .&. y
65 test16 x y = x .|. y .&. y
66
66
67+ test17 :: Number
68+ test17 = negate (-1)
69+
70+ test18 :: Number
71+ test18 = negate $ negate 1
72+
73+ test19 :: Number
74+ test19 = negate $ negate (-1)
75+
67 main = do
76 main = do
68 let t1 = test1 1 2 (\x y -> x + y)
77 let t1 = test1 1 2 (\x y -> x + y)
69 let t2 = test2
78 let t2 = test2
@@ -81,4 +90,7 @@ module Main where
81 let t14 = test14 1 2
90 let t14 = test14 1 2
82 let t15 = test15 1 2
91 let t15 = test15 1 2
83 let t16 = test16 1 2
92 let t16 = test16 1 2
93+ let t17 = test17
94+ let t18 = test18
95+ let t19 = test19
84 trace "Done"
96 trace "Done"
src/Language/PureScript/Pretty/JS.hs+13−4
@@ -209,15 +209,24 @@ instanceOf = mkPattern match
209 match (JSInstanceOf val ty) = Just (val, ty)
209 match (JSInstanceOf val ty) = Just (val, ty)
210 match _ = Nothing
210 match _ = Nothing
211
211
212−unary :: UnaryOperator -> String -> Operator PrinterState JS String
212+unary' :: UnaryOperator -> (JS -> String) -> Operator PrinterState JS String
213−unary op str = Wrap match (++)
213+unary' op mkStr = Wrap match (++)
214 where
214 where
215 match :: Pattern PrinterState JS (String, JS)
215 match :: Pattern PrinterState JS (String, JS)
216 match = mkPattern match'
216 match = mkPattern match'
217 where
217 where
218− match' (JSUnary op' val) | op' == op = Just (str, val)
218+ match' (JSUnary op' val) | op' == op = Just (mkStr val, val)
219 match' _ = Nothing
219 match' _ = Nothing
220
220
221+unary :: UnaryOperator -> String -> Operator PrinterState JS String
222+unary op str = unary' op (const str)
223+
224+negateOperator :: Operator PrinterState JS String
225+negateOperator = unary' Negate (\v -> if isNegate v then "- " else "-")
226+ where
227+ isNegate (JSUnary Negate _) = True
228+ isNegate _ = False
229+
221binary :: BinaryOperator -> String -> Operator PrinterState JS String
230binary :: BinaryOperator -> String -> Operator PrinterState JS String
222binary op str = AssocL match (\v1 v2 -> v1 ++ " " ++ str ++ " " ++ v2)
231binary op str = AssocL match (\v1 v2 -> v1 ++ " " ++ str ++ " " ++ v2)
223 where
232 where
@@ -271,7 +280,7 @@ prettyPrintJS' = A.runKleisli $ runPattern matchValue
271 , [ AssocR instanceOf $ \v1 v2 -> v1 ++ " instanceof " ++ v2 ]
280 , [ AssocR instanceOf $ \v1 v2 -> v1 ++ " instanceof " ++ v2 ]
272 , [ unary Not "!" ]
281 , [ unary Not "!" ]
273 , [ unary BitwiseNot "~" ]
282 , [ unary BitwiseNot "~" ]
274− , [ unary Negate "-" ]
283+ , [ negateOperator ]
275 , [ unary Positive "+" ]
284 , [ unary Positive "+" ]
276 , [ binary Multiply "*"
285 , [ binary Multiply "*"
277 , binary Divide "/"
286 , binary Divide "/"
src/Language/PureScript/Sugar/Operators.hs−2
@@ -58,8 +58,6 @@ removeSignedLiterals (Module mn ds exts) = Module mn (map f' ds) exts
58 where
58 where
59 (f', _, _) = everywhereOnValues id go id
59 (f', _, _) = everywhereOnValues id go id
60
60
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
61 go (UnaryMinus val) = App (Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.negate))) val
64 go other = other
62 go other = other
65
63