git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Mixed function argument syntax
46189ddPhil Freeman
examples/passing/Functions.psnew file+11
@@ -0,0 +1,11 @@
1+test1 = \ -> 0
2+
3+test2 = \() -> 0
4+
5+test3 = \a (b, c) d -> a + b + c + d
6+
7+test4 = \(a) -> a
8+
9+test5 = \(%%) -> 1 %% 2
10+
11+test6 = \((+++), (***)) -> 1 +++ 2 *** 3
src/Language/PureScript/Parser/Values.hs+13−13
@@ -59,20 +59,20 @@ parseIdentifierAndValue = (,) <$> (C.indented *> C.identifier <* C.indented <* C
59parseAbs :: P.Parsec String ParseState Value
59parseAbs :: P.Parsec String ParseState Value
60parseAbs = do
60parseAbs = do
61 C.lexeme $ P.char '\\'
61 C.lexeme $ P.char '\\'
62− uncurriedAbs <|> curriedAbs
62+ args <- P.many (C.indented *> (P.try singleArg <|> manyArgs))
63+ C.lexeme $ C.indented *> P.string "->"
64+ value <- parseValue
65+ return $ toFunction args value
63 where
66 where
64− uncurriedAbs :: P.Parsec String ParseState Value
67+ manyArgs :: P.Parsec String ParseState (Value -> Value)
65− uncurriedAbs = do
68+ manyArgs = do
66− args <- C.indented *> C.parens ((C.indented *> C.parseIdent) `P.sepBy` (C.indented *> C.comma))
69+ args <- C.parens ((C.indented *> C.parseIdent) `P.sepBy` (C.indented *> C.comma))
67− C.lexeme $ C.indented *> P.string "->"
68− value <- parseValue
69− return $ Abs args value
70+ return $ Abs args
70− curriedAbs :: P.Parsec String ParseState Value
71+ singleArg :: P.Parsec String ParseState (Value -> Value)
71− curriedAbs = do
72+ singleArg = Abs . return <$> C.parseIdent
72− args <- P.many1 (C.indented *> C.parseIdent)
73+ toFunction :: [Value -> Value] -> Value -> Value
73− C.lexeme $ C.indented *> P.string "->"
74+ toFunction [] value = Abs [] value
74− value <- parseValue
75+ toFunction args value = foldr (($)) value args
75− return $ foldl (\ret arg -> Abs [arg] ret) value args
76
76
77parseApp :: P.Parsec String ParseState Value
77parseApp :: P.Parsec String ParseState Value
78parseApp = App <$> parseValue
78parseApp = App <$> parseValue
src/Language/PureScript/Pretty/JS.hs+1−1
@@ -115,7 +115,7 @@ prettyPrintJS = fromMaybe (error "Incomplete pattern") . pattern matchValue
115 , [ Wrap app $ \args val -> val ++ "(" ++ args ++ ")" ]
115 , [ Wrap app $ \args val -> val ++ "(" ++ args ++ ")" ]
116 , [ Wrap lam $ \(name, args) ret -> "function "
116 , [ Wrap lam $ \(name, args) ret -> "function "
117 ++ maybe "" identToJs name
117 ++ maybe "" identToJs name
118− ++ "(" ++ intercalate "," (map identToJs args) ++ ") "
118+ ++ "(" ++ intercalate ", " (map identToJs args) ++ ") "
119 ++ ret ]
119 ++ ret ]
120 , [ Wrap conditional $ \(th, el) cond -> cond ++ " ? " ++ prettyPrintJS th ++ " : " ++ prettyPrintJS el ]
120 , [ Wrap conditional $ \(th, el) cond -> cond ++ " ? " ++ prettyPrintJS th ++ " : " ++ prettyPrintJS el ]
121 , [ binary LessThan "<" ]
121 , [ binary LessThan "<" ]