git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use braces for blocks, instead of the do keyword
aa13d6dPhil Freeman
examples/passing/Assign.purs+7−5
@@ -1,5 +1,7 @@
1−sum = \n -> do
1+sum = \n -> {
2− var x = 0
2+ var x = 0;
3− for i <- 0 until n:
3+ for (i <- 0 until n) {
4− x = x + i
4+ x = x + i;
5+ }
5− return x
6+ return x;
7+ }
examples/passing/Console.purs+9−5
@@ -9,11 +9,15 @@ foreign import (>>=) :: forall a b. IO a -> (a -> IO b) -> IO b
9foreign import putStrLn :: String -> IO {}
9foreign import putStrLn :: String -> IO {}
10
10
11replicateM_ :: forall a. Number -> IO a -> IO {}
11replicateM_ :: forall a. Number -> IO a -> IO {}
12−replicateM_ = \n -> \x -> do
12+replicateM_ = \n -> \x ->
13+ {
13− var io = ret {}
14+ var io = ret {};
14− for i <- 0 until n:
15+ for (i <- 0 until n)
16+ {
15− io = x *> io
17+ io = x *> io;
18+ }
16− return io
19+ return io;
20+ }
17
21
18main = replicateM_ 10 (putStrLn "Hello World!")
22main = replicateM_ 10 (putStrLn "Hello World!")
19
23
examples/passing/Foreach.purs+7−5
@@ -1,5 +1,7 @@
1−sum = \ns -> do
1+sum = \ns -> {
2− var total = 0
2+ var total = 0;
3− foreach n in ns:
3+ foreach (n in ns) {
4− total = total + n
4+ total = total + n;
5+ }
5− return total
6+ return total;
7+ }
examples/passing/IfThenElse.purs+32−22
@@ -1,24 +1,34 @@
1−testIf = do
1+testIf =
2+ {
2− var x = 0
3+ var x = 0;
3− if x == 0:
4+ if (x == 0) {
4− x = x + 1
5+ x = x + 1;
6+ }
5− return x
7+ return x;
8+ }
6
9
7−testIfElse = do
10+testIfElse =
11+ {
8− var x = 0
12+ var x = 0;
9− if x == 0:
13+ if (x == 0) {
10− x = x + 1
14+ x = x + 1;
11− else:
15+ } else {
12− x = x - 1
16+ x = x - 1;
17+ }
13− return x
18+ return x;
19+ }
14
20
15−testIfElseIf = \x -> do
21+testIfElseIf = \x ->
22+ {
16− var y = x
23+ var y = x;
17− while y > 1:
24+ while (y > 1) {
18− if y % 3 == 0:
25+ if (y % 3 == 0) {
19− y = y / 3
26+ y = y / 3;
20− else if y % 3 == 1:
27+ } else if (y % 3 == 1) {
21− y = (y - 1) % 3
28+ y = (y - 1) % 3;
22− else:
29+ } else {
23− y = y * 4 + 1
30+ y = y * 4 + 1;
31+ }
32+ }
24− return y
33+ return y;
34+ }
examples/passing/TypeDecl.purs+7−5
@@ -5,8 +5,10 @@ k :: String -> Number -> String
5k = \x -> \y -> x
5k = \x -> \y -> x
6
6
7iterate :: forall a. Number -> (a -> a) -> a -> a
7iterate :: forall a. Number -> (a -> a) -> a -> a
8−iterate = \n -> \f -> \a -> do
8+iterate = \n -> \f -> \a -> {
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+ }
12− return result
13+ return result;
14+ }
examples/passing/TypeSynonyms.purs+6−4
@@ -6,10 +6,12 @@ type Lens a b =
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 ->
10+ {
10− var b = l1.get a
11+ var b = l1.get a;
11− var b1 = l2.set b c
12+ var b1 = l2.set b c;
12− return l1.set a b1
13+ return l1.set a b1;
14+ }
13 }
15 }
14
16
15type Pair a b = { fst :: a, snd :: b }
17type Pair a b = { fst :: a, snd :: b }
libraries/jquery/example.purs+6−5
@@ -1,5 +1,6 @@
1−main = do
1+main = {
2− var div = create "<div>"
2+ var div = create "<div>";
3− div = div `appendText` "Hello World!" `css` { color: "#FF0000" }
3+ div = div `appendText` "Hello World!" `css` { color: "#FF0000" };
4− div = div `appendTo` select "body"
4+ div = div `appendTo` select "body";
5− return { }
5+ return { };
6+ }
libraries/prelude/prelude.purs+37−25
@@ -68,11 +68,13 @@ foldr = \f -> \a -> \bs -> case bs of
68 [] -> a
68 [] -> a
69
69
70foldl :: forall a b. (a -> b -> b) -> b -> [a] -> b
70foldl :: forall a b. (a -> b -> b) -> b -> [a] -> b
71−foldl = \f -> \b -> \as -> do
71+foldl = \f -> \b -> \as -> {
72− var result = b
72+ var result = b;
73− foreach a in as:
73+ foreach (a in as) {
74− result = f a result
74+ result = f a result;
75+ }
75− return result
76+ return result;
77+ }
76
78
77foreign import member "length" length :: forall a. [a] -> Number
79foreign import member "length" length :: forall a. [a] -> Number
78
80
@@ -102,11 +104,13 @@ cons :: forall a. a -> [a] -> [a]
102cons = \a -> concat([a])
104cons = \a -> concat([a])
103
105
104concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
106concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
105−concatMap = \as -> \f -> do
107+concatMap = \as -> \f -> {
106− var result = []
108+ var result = [];
107− foreach a in as:
109+ foreach (a in as) {
108− result = result `concat` f a
110+ result = result `concat` f a;
111+ }
109− return result
112+ return result;
113+ }
110
114
111foreign import filter :: forall a. [a] -> (a -> Boolean) -> [a]
115foreign import filter :: forall a. [a] -> (a -> Boolean) -> [a]
112
116
@@ -116,11 +120,13 @@ empty = \as -> case as of
116 _ -> false
120 _ -> false
117
121
118range :: Number -> Number -> [Number]
122range :: Number -> Number -> [Number]
119−range = \lo -> \hi -> do
123+range = \lo -> \hi -> {
120− var ns = []
124+ var ns = [];
121− for n <- lo until hi:
125+ for (n <- lo until hi) {
122− ns = push ns n
126+ ns = push ns n;
127+ }
123− return ns
128+ return ns;
129+ }
124
130
125zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
131zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
126zipWith = \f -> \as -> \bs -> case { as: as, bs: bs } of
132zipWith = \f -> \as -> \bs -> case { as: as, bs: bs } of
@@ -128,18 +134,24 @@ zipWith = \f -> \as -> \bs -> case { as: as, bs: bs } of
128 _ -> []
134 _ -> []
129
135
130any :: forall a. (a -> Boolean) -> [a] -> Boolean
136any :: forall a. (a -> Boolean) -> [a] -> Boolean
131−any = \p -> \as -> do
137+any = \p -> \as -> {
132− for i <- 0 until length as:
138+ for (i <- 0 until length as) {
133− if p (as !! i):
139+ if (p (as !! i)) {
134− return true
140+ return true;
141+ }
142+ }
135− return false
143+ return false;
144+ }
136
145
137all :: forall a. (a -> Boolean) -> [a] -> Boolean
146all :: forall a. (a -> Boolean) -> [a] -> Boolean
138−all = \p -> \as -> do
147+all = \p -> \as -> {
139− for i <- 0 until length as:
148+ for (i <- 0 until length as) {
140− if !(p (as !! i)):
149+ if (!(p (as !! i))) {
141− return false
150+ return false;
151+ }
152+ }
142− return true
153+ return true;
154+ }
143
155
144-- Pairs
156-- Pairs
145
157
purescript.cabal+1−1
@@ -1,5 +1,5 @@
1name: purescript
1name: purescript
2−version: 0.1.15
2+version: 0.1.16
3cabal-version: >=1.8
3cabal-version: >=1.8
4build-type: Simple
4build-type: Simple
5license: MIT
5license: MIT
src/Language/PureScript/Parser/Values.hs+21−14
@@ -86,10 +86,15 @@ parseIfThenElse = IfThenElse <$> (P.try (C.reserved "if") *> C.indented *> parse
86 <*> (C.indented *> C.reserved "else" *> C.indented *> parseValue)
86 <*> (C.indented *> C.reserved "else" *> C.indented *> parseValue)
87
87
88parseBlock :: P.Parsec String ParseState Value
88parseBlock :: P.Parsec String ParseState Value
89−parseBlock = Block <$> (P.try (C.reserved "do") *> parseManyStatements)
89+parseBlock = Block <$> parseManyStatements
90
90
91parseManyStatements :: P.Parsec String ParseState [Statement]
91parseManyStatements :: P.Parsec String ParseState [Statement]
92+parseManyStatements = (do
93+ C.lexeme $ P.char '{'
94+ C.indented
92−parseManyStatements = C.indented *> C.mark (P.many (C.same *> C.mark parseStatement)) P.<?> "block"
95+ sts <- C.mark (P.many (C.same *> C.mark parseStatement))
96+ C.lexeme (P.char '}')
97+ return sts) P.<?> "block"
93
98
94parseValueAtom :: P.Parsec String ParseState Value
99parseValueAtom :: P.Parsec String ParseState Value
95parseValueAtom = C.indented *> P.choice
100parseValueAtom = C.indented *> P.choice
@@ -97,7 +102,7 @@ parseValueAtom = C.indented *> P.choice
97 , P.try parseStringLiteral
102 , P.try parseStringLiteral
98 , P.try parseBooleanLiteral
103 , P.try parseBooleanLiteral
99 , parseArrayLiteral
104 , parseArrayLiteral
100− , parseObjectLiteral
105+ , P.try parseObjectLiteral
101 , parseAbs
106 , parseAbs
102 , P.try parseConstructor
107 , P.try parseConstructor
103 , P.try parseVar
108 , P.try parseVar
@@ -143,6 +148,7 @@ parseVariableIntroduction = do
143 name <- C.indented *> C.parseIdent
148 name <- C.indented *> C.parseIdent
144 C.lexeme $ C.indented *> P.char '='
149 C.lexeme $ C.indented *> P.char '='
145 value <- parseValue
150 value <- parseValue
151+ C.indented *> C.semi
146 return $ VariableIntroduction name value
152 return $ VariableIntroduction name value
147
153
148parseAssignment :: P.Parsec String ParseState Statement
154parseAssignment :: P.Parsec String ParseState Statement
@@ -150,21 +156,22 @@ parseAssignment = do
150 tgt <- C.parseIdent
156 tgt <- C.parseIdent
151 C.lexeme $ C.indented *> P.char '='
157 C.lexeme $ C.indented *> P.char '='
152 value <- parseValue
158 value <- parseValue
159+ C.indented *> C.semi
153 return $ Assignment tgt value
160 return $ Assignment tgt value
154
161
155parseWhile :: P.Parsec String ParseState Statement
162parseWhile :: P.Parsec String ParseState Statement
156−parseWhile = While <$> (C.reserved "while" *> C.indented *> parseValue <* C.indented <* C.colon)
163+parseWhile = While <$> (C.reserved "while" *> C.indented *> C.parens parseValue)
157− <*> parseManyStatements
164+ <*> (C.indented *> parseManyStatements)
158
165
159parseFor :: P.Parsec String ParseState Statement
166parseFor :: P.Parsec String ParseState Statement
160−parseFor = For <$> (C.reserved "for" *> C.indented *> C.parseIdent)
167+parseFor = For <$> (C.reserved "for" *> C.indented *> C.lexeme (P.char '(') *> C.indented *> C.parseIdent)
161 <*> (C.indented *> C.lexeme (P.string "<-") *> parseValue)
168 <*> (C.indented *> C.lexeme (P.string "<-") *> parseValue)
162− <*> (C.indented *> C.reserved "until" *> parseValue <* C.indented <* C.colon)
169+ <*> (C.indented *> C.reserved "until" *> parseValue <* C.indented <* C.lexeme (P.char ')'))
163 <*> parseManyStatements
170 <*> parseManyStatements
164
171
165parseForEach :: P.Parsec String ParseState Statement
172parseForEach :: P.Parsec String ParseState Statement
166−parseForEach = ForEach <$> (C.reserved "foreach" *> C.indented *> C.parseIdent)
173+parseForEach = ForEach <$> (C.reserved "foreach" *> C.indented *> C.lexeme (P.char '(') *> C.indented *> C.parseIdent)
167− <*> (C.indented *> C.reserved "in" *> parseValue <* C.indented <* C.colon)
174+ <*> (C.indented *> C.reserved "in" *> parseValue <* C.lexeme (P.char ')'))
168 <*> parseManyStatements
175 <*> parseManyStatements
169
176
170parseIf :: P.Parsec String ParseState Statement
177parseIf :: P.Parsec String ParseState Statement
@@ -172,16 +179,16 @@ parseIf = If <$> parseIfStatement
172
179
173parseIfStatement :: P.Parsec String ParseState IfStatement
180parseIfStatement :: P.Parsec String ParseState IfStatement
174parseIfStatement =
181parseIfStatement =
175− IfStatement <$> (C.reserved "if" *> C.indented *> parseValue <* C.indented <* C.colon)
182+ IfStatement <$> (C.reserved "if" *> C.indented *> C.parens parseValue)
176 <*> parseManyStatements
183 <*> parseManyStatements
177− <*> P.optionMaybe (C.same *> parseElseStatement)
184+ <*> P.optionMaybe parseElseStatement
178
185
179parseElseStatement :: P.Parsec String ParseState ElseStatement
186parseElseStatement :: P.Parsec String ParseState ElseStatement
180−parseElseStatement = C.reserved "else" >> (ElseIf <$> (C.indented *> parseIfStatement)
187+parseElseStatement = C.reserved "else" >> (ElseIf <$> parseIfStatement
181− <|> Else <$> (C.indented *> C.colon *> parseManyStatements))
188+ <|> Else <$> parseManyStatements)
182
189
183parseReturn :: P.Parsec String ParseState Statement
190parseReturn :: P.Parsec String ParseState Statement
184−parseReturn = Return <$> (C.reserved "return" *> parseValue)
191+parseReturn = Return <$> (C.reserved "return" *> parseValue <* C.indented <* C.semi)
185
192
186parseStatement :: P.Parsec String ParseState Statement
193parseStatement :: P.Parsec String ParseState Statement
187parseStatement = P.choice (map P.try
194parseStatement = P.choice (map P.try