git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Better syntax for single function application
ca13b3aPhil Freeman
examples/Console.ps+2−2
@@ -10,10 +10,10 @@ extern putStrLn :: String -> IO {}
10
10
11replicateM_ :: forall a. Number -> IO a -> IO {}
11replicateM_ :: forall a. Number -> IO a -> IO {}
12replicateM_ = \n -> \x -> do
12replicateM_ = \n -> \x -> do
13− var io = ret({})
13+ var io = ret {}
14 for i <- 0 until n:
14 for i <- 0 until n:
15 io = x *> io
15 io = x *> io
16 return io
16 return io
17
17
18−main = replicateM_(10)(putStrLn("Hello World!"))
18+main = replicateM_ 10 (putStrLn "Hello World!")
19
19
examples/List.ps+4−4
@@ -11,12 +11,12 @@ isNull = \l -> case l of
11
11
12concat = \l1 -> \l2 -> case l1 of
12concat = \l1 -> \l2 -> case l1 of
13 Nil -> l2
13 Nil -> l2
14− Cons x -> Cons(
14+ Cons x -> Cons
15 { head: x.head
15 { head: x.head
16− , tail: concat(x.tail)(l2)
16+ , tail: concat x.tail l2
17− })
17+ }
18
18
19flatten = \xss -> case xss of
19flatten = \xss -> case xss of
20 Nil -> Nil
20 Nil -> Nil
21− Cons cons -> concat(cons.head)(flatten(cons.tail))
21+ Cons cons -> concat cons.head (flatten cons.tail)
22
22
examples/Maybe.ps+3−3
@@ -3,8 +3,8 @@ data Maybe a = Nothing | Just a
3maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
3maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
4maybe = \b -> \f -> \m -> case m of
4maybe = \b -> \f -> \m -> case m of
5 Nothing -> b
5 Nothing -> b
6− Just a -> f(a)
6+ Just a -> f a
7
7
8−fmap = \m -> \f -> maybe(Nothing)(\a -> Just(f(a)))(m)
8+fmap = \m -> \f -> maybe Nothing (\a -> Just (f a)) m
9
9
10−bind = \m -> \f -> maybe(Nothing)(f)(m)
10+bind = \m -> \f -> maybe Nothing f m
examples/Objects.ps+2−2
@@ -4,6 +4,6 @@ append = \o -> { foo: o.foo, bar: 1 }
4
4
5apTest = append({foo : "Foo", baz: "Baz"})
5apTest = append({foo : "Foo", baz: "Baz"})
6
6
7−f = (\a -> a.b.c)({ b: { c: 1, d: "Hello" }, e: "World" })
7+f = (\a -> a.b.c) { b: { c: 1, d: "Hello" }, e: "World" }
8
8
9−g = (\a -> a.f({ x: 1, y: "y" }))({ f: \o -> o.x + 1 })
9+g = (\a -> a.f { x: 1, y: "y" }) { f: \o -> o.x + 1 }
examples/Operators.ps+2−2
@@ -1,6 +1,6 @@
1test1 = \x, y, z -> x * y + z(x)(y)
1test1 = \x, y, z -> x * y + z(x)(y)
2
2
3−test2 = (\x -> x.foo(false))({ foo : \_ -> 1 })
3+test2 = (\x -> x.foo false) { foo : \_ -> 1 }
4
4
5test3 = (\x, y -> x)(1 + 2 * (1 + 2), true && (false || false))
5test3 = (\x, y -> x)(1 + 2 * (1 + 2), true && (false || false))
6
6
@@ -12,4 +12,4 @@ test4 = 1 `k` 2
12
12
13test5 = 1 %% 2 %% 3
13test5 = 1 %% 2 %% 3
14
14
15−test6 = ((\x -> x) `k` 2) (3)
15+test6 = ((\x -> x) `k` 2) 3
examples/ReadShow.ps+1−1
@@ -2,4 +2,4 @@ extern read :: forall a. String -> a
2
2
3extern show :: forall a. a -> String
3extern show :: forall a. a -> String
4
4
5−test = \x -> show(read(x))
5+test = \x -> show (read x)
examples/TypeDecl.ps+3−3
@@ -1,12 +1,12 @@
1id :: forall a. (a) -> a
1id :: forall a. (a) -> a
2id = \x -> x
2id = \x -> x
3
3
4−k :: (String) -> (Number) -> String
4+k :: String -> Number -> String
5k = \x -> \y -> x
5k = \x -> \y -> x
6
6
7−iterate :: forall a. (Number) -> ((a) -> a) -> (a) -> a
7+iterate :: forall a. Number -> (a -> a) -> a -> a
8iterate = \n -> \f -> \a -> do
8iterate = \n -> \f -> \a -> do
9 var result = a
9 var result = a
10 for i <- 0 until n:
10 for i <- 0 until n:
11− result = f(result)
11+ result = f result
12 return result
12 return result
examples/TypeSynonyms.ps+4−4
@@ -5,9 +5,9 @@ type Lens a b =
5
5
6composeLenses :: forall a b c. Lens a b -> Lens b c -> Lens a c
6composeLenses :: forall a b c. Lens a b -> Lens b c -> Lens a c
7composeLenses = \l1 -> \l2 ->
7composeLenses = \l1 -> \l2 ->
8− { get: \a -> l2.get(l1.get(a))
8+ { get: \a -> l2.get (l1.get a)
9 , set: \a -> \c -> do
9 , set: \a -> \c -> do
10− var b = l1.get(a)
10+ var b = l1.get a
11− var b1 = l2.set(b)(c)
11+ var b1 = l2.set b c
12− return l1.set(a)(b1)
12+ return l1.set a b1
13 }
13 }
src/PureScript/CodeGen/JS.hs+1−1
@@ -170,7 +170,7 @@ binderToJs :: String -> String -> Binder -> Gen String
170binderToJs varName done (StringBinder str) =
170binderToJs varName done (StringBinder str) =
171 return $ "if (" ++ varName ++ " === \"" ++ str ++ "\") {" ++ done ++ " }"
171 return $ "if (" ++ varName ++ " === \"" ++ str ++ "\") {" ++ done ++ " }"
172binderToJs varName done (NumberBinder num) =
172binderToJs varName done (NumberBinder num) =
173− return $ "if (" ++ varName ++ " === \"" ++ either show show num ++ "\") {" ++ done ++ " }"
173+ return $ "if (" ++ varName ++ " === " ++ either show show num ++ ") {" ++ done ++ " }"
174binderToJs varName done (BooleanBinder True) =
174binderToJs varName done (BooleanBinder True) =
175 return $ "if (" ++ varName ++ ") {" ++ done ++ " }"
175 return $ "if (" ++ varName ++ ") {" ++ done ++ " }"
176binderToJs varName done (BooleanBinder False) =
176binderToJs varName done (BooleanBinder False) =
src/PureScript/Parser/Common.hs+3−2
@@ -28,6 +28,7 @@ import PureScript.Names
28
28
29reservedNames :: [String]
29reservedNames :: [String]
30reservedNames = [ "case"
30reservedNames = [ "case"
31+ , "of"
31 , "data"
32 , "data"
32 , "type"
33 , "type"
33 , "var"
34 , "var"
@@ -69,7 +70,7 @@ reservedNames = [ "case"
69
70
70reservedOpNames :: [String]
71reservedOpNames :: [String]
71reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
72reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
72− , "==", "!=", "&", "^", "|", "&&", "||" ]
73+ , "==", "!=", "&", "^", "|", "&&", "||", "->" ]
73
74
74identStart :: P.Parsec String u Char
75identStart :: P.Parsec String u Char
75identStart = P.lower <|> P.oneOf "_$"
76identStart = P.lower <|> P.oneOf "_$"
@@ -129,7 +130,7 @@ properName :: P.Parsec String u String
129properName = lexeme $ P.try ((:) <$> P.upper <*> many (PT.identLetter langDef) P.<?> "name")
130properName = lexeme $ P.try ((:) <$> P.upper <*> many (PT.identLetter langDef) P.<?> "name")
130
131
131integerOrFloat :: P.Parsec String u (Either Integer Double)
132integerOrFloat :: P.Parsec String u (Either Integer Double)
132−integerOrFloat = Left <$> P.try (PT.integer tokenParser) <|>
133+integerOrFloat = Left <$> P.try (PT.natural tokenParser) <|>
133 Right <$> P.try (PT.float tokenParser)
134 Right <$> P.try (PT.float tokenParser)
134
135
135augment :: P.Stream s m t => P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
136augment :: P.Stream s m t => P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
src/PureScript/Parser/Values.hs+9−6
@@ -95,15 +95,18 @@ parseValueAtom = C.indented *> P.choice (map P.try
95 , C.parens parseValue ])
95 , C.parens parseValue ])
96
96
97parseValue :: P.Parsec String P.Column Value
97parseValue :: P.Parsec String P.Column Value
98−parseValue = buildExpressionParser operators . C.buildPostfixParser postfixTable $ parseValueAtom
98+parseValue = buildExpressionParser operators . C.buildPostfixParser postfixTable2 $ indexersAndAccessors
99 where
99 where
100+ indexersAndAccessors = C.buildPostfixParser postfixTable1 $ parseValueAtom
100− postfixTable = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
101+ postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
101− , Indexer <$> (C.indented *> C.squares parseValue)
102+ , Indexer <$> (C.indented *> C.squares parseValue) ]
103+ postfixTable2 = [ C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2])
102− , flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
104+ , flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
103− , flip TypedValue <$> (P.try $ C.lexeme (C.indented *> P.string "::") *> parsePolyType) ]
105+ , flip TypedValue <$> (P.try $ C.lexeme (C.indented *> P.string "::") *> parsePolyType) ]
104 operators = [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
106 operators = [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
105 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "~") >> return (Unary BitwiseNot)
107 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "~") >> return (Unary BitwiseNot)
106− , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "-") >> return (Unary Negate) ]
108+ , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "-") >> return (Unary Negate)
109+ , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "+") >> return id ]
107 , [ Infix (C.lexeme (P.try (C.indented *> C.parseIdentInfix) >>= \ident -> return $ \t1 t2 -> App (App (Var ident) [t1]) [t2])) AssocRight ]
110 , [ Infix (C.lexeme (P.try (C.indented *> C.parseIdentInfix) >>= \ident -> return $ \t1 t2 -> App (App (Var ident) [t1]) [t2])) AssocRight ]
108 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<=") >> return (Binary LessThanOrEqualTo)) AssocRight
111 , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<=") >> return (Binary LessThanOrEqualTo)) AssocRight
109 , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">=") >> return (Binary GreaterThanOrEqualTo)) AssocRight ]
112 , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">=") >> return (Binary GreaterThanOrEqualTo)) AssocRight ]