git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Curried function argument syntax
commit6f3f8a98c94f5a9feabb9d415ea4240899d88c67 authorPhil Freeman <paf31@cantab.net> dateThu 7 Nov 2013, 13:07 (13 years ago) parente8ec471
5 files changed+19−9
examples/passing/Arrays.ps+1−1 examples/passing/Guards.ps+1−1 examples/passing/Operators.ps+2−2 examples/passing/s.ps+1−1 src/Language/PureScript/Parser/Values.hs+14−4
examples/passing/Arrays.ps+1−1
@@ -8,7 +8,7 @@ test2 = \arr -> case arr of
88
99data Tree = One Number | Some [Tree]
1010
11−test3 = \tree, sum -> case tree of
11+test3 = \(tree, sum) -> case tree of
1212 One n -> n
1313 Some [n1, n2 : rest] -> test3(n1, sum) * 10 + test3(n2, sum) * 5 + sum(rest)
1414
examples/passing/Guards.ps+1−1
@@ -3,6 +3,6 @@ collatz = \x -> case x of
33 y -> y * 3 + 1
44
55-- Guards have access to current scope
6−collatz2 = \x, y -> case x of
6+collatz2 = \x y -> case x of
77 z | y > 0 -> z / 2
88 z -> z * 3 + 1
examples/passing/Operators.ps+2−2
@@ -1,8 +1,8 @@
1−test1 = \x, y, z -> x * y + z(x)(y)
1+test1 = \(x, y, z) -> x * y + z(x)(y)
22
33test2 = (\x -> x.foo false) { foo : \_ -> 1 }
44
5−test3 = (\x, y -> x)(1 + 2 * (1 + 2), true && (false || false))
5+test3 = (\(x, y) -> x)(1 + 2 * (1 + 2), true && (false || false))
66
77k = \x -> \y -> x
88
examples/passing/s.ps+1−1
@@ -1 +1 @@
1−s = \x, y, z -> x z (y z)
1+s = \x y z -> x z (y z)
src/Language/PureScript/Parser/Values.hs+14−4
@@ -59,10 +59,20 @@ parseIdentifierAndValue = (,) <$> (C.indented *> C.identifier <* C.indented <* C
5959parseAbs :: P.Parsec String ParseState Value
6060parseAbs = do
6161 C.lexeme $ P.char '\\'
62− args <- (C.indented *> C.parseIdent) `P.sepBy` (C.indented *> C.comma)
63− C.lexeme $ C.indented *> P.string "->"
64− value <- parseValue
65− return $ Abs args value
62+ uncurriedAbs <|> curriedAbs
63+ where
64+ uncurriedAbs :: P.Parsec String ParseState Value
65+ uncurriedAbs = do
66+ args <- C.indented *> 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+ curriedAbs :: P.Parsec String ParseState Value
71+ curriedAbs = do
72+ args <- P.many1 (C.indented *> C.parseIdent)
73+ C.lexeme $ C.indented *> P.string "->"
74+ value <- parseValue
75+ return $ foldl (\ret arg -> Abs [arg] ret) value args
6676
6777parseApp :: P.Parsec String ParseState Value
6878parseApp = App <$> parseValue