git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Curried function argument syntax
6f3f8a9Phil Freeman
examples/passing/Arrays.ps+1−1
@@ -8,7 +8,7 @@ test2 = \arr -> case arr of
8
8
9data Tree = One Number | Some [Tree]
9data Tree = One Number | Some [Tree]
10
10
11−test3 = \tree, sum -> case tree of
11+test3 = \(tree, sum) -> case tree of
12 One n -> n
12 One n -> n
13 Some [n1, n2 : rest] -> test3(n1, sum) * 10 + test3(n2, sum) * 5 + sum(rest)
13 Some [n1, n2 : rest] -> test3(n1, sum) * 10 + test3(n2, sum) * 5 + sum(rest)
14
14
examples/passing/Guards.ps+1−1
@@ -3,6 +3,6 @@ collatz = \x -> case x of
3 y -> y * 3 + 1
3 y -> y * 3 + 1
4
4
5-- Guards have access to current scope
5-- Guards have access to current scope
6−collatz2 = \x, y -> case x of
6+collatz2 = \x y -> case x of
7 z | y > 0 -> z / 2
7 z | y > 0 -> z / 2
8 z -> z * 3 + 1
8 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)
2
2
3test2 = (\x -> x.foo false) { foo : \_ -> 1 }
3test2 = (\x -> x.foo false) { foo : \_ -> 1 }
4
4
5−test3 = (\x, y -> x)(1 + 2 * (1 + 2), true && (false || false))
5+test3 = (\(x, y) -> x)(1 + 2 * (1 + 2), true && (false || false))
6
6
7k = \x -> \y -> x
7k = \x -> \y -> x
8
8
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
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
63+ where
64+ uncurriedAbs :: P.Parsec String ParseState Value
65+ uncurriedAbs = do
62− args <- (C.indented *> C.parseIdent) `P.sepBy` (C.indented *> C.comma)
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)
63− C.lexeme $ C.indented *> P.string "->"
73+ C.lexeme $ C.indented *> P.string "->"
64− value <- parseValue
74+ value <- parseValue
65− return $ Abs args value
75+ return $ foldl (\ret arg -> Abs [arg] ret) value args
66
76
67parseApp :: P.Parsec String ParseState Value
77parseApp :: P.Parsec String ParseState Value
68parseApp = App <$> parseValue
78parseApp = App <$> parseValue