git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #809 from davidchambers/triple-quotes
145c4c5Phil Freeman
examples/passing/BindersInFunctions.purs+5−3
@@ -5,9 +5,11 @@ import Prelude
5tail = \(_:xs) -> xs
5tail = \(_:xs) -> xs
6
6
7foreign import error
7foreign import error
8+ """
8− "function error(msg) {\
9+ function error(msg) {
9− \ throw msg;\
10+ throw msg;
11+ }
10− \}" :: forall a. String -> a
12+ """ :: forall a. String -> a
11
13
12main =
14main =
13 let ts = tail [1, 2, 3] in
15 let ts = tail [1, 2, 3] in
examples/passing/CheckSynonymBug.purs+5−3
@@ -5,9 +5,11 @@ module Main where
5 type Foo a = [a]
5 type Foo a = [a]
6
6
7 foreign import length
7 foreign import length
8+ """
8− "function length(a) {\
9+ function length(a) {
9− \ return a.length;\
10+ return a.length;
11+ }
10− \}" :: forall a. [a] -> Number
12+ """ :: forall a. [a] -> Number
11
13
12 foo _ = length ([] :: Foo Number)
14 foo _ = length ([] :: Foo Number)
13
15
examples/passing/Comparisons.purs+8−6
@@ -6,12 +6,14 @@ import Debug.Trace
6foreign import data Assert :: !
6foreign import data Assert :: !
7
7
8foreign import assert
8foreign import assert
9+ """
9− "function assert(x) {\
10+ function assert(x) {
10− \ return function () {\
11+ return function() {
11− \ if (!x) throw new Error('assertion failed');\
12+ if (!x) throw new Error('assertion failed');
12− \ return {};\
13+ return {};
13− \ };\
14+ };
15+ }
14− \};" :: forall e. Boolean -> Eff (assert :: Assert | e) Unit
16+ """ :: forall e. Boolean -> Eff (assert :: Assert | e) Unit
15
17
16main = do
18main = do
17 assert (1 < 2)
19 assert (1 < 2)
examples/passing/DeepArrayBinder.purs+5−3
@@ -7,9 +7,11 @@ match2 (x : y : xs) = x * y + match2 xs
7match2 _ = 0
7match2 _ = 0
8
8
9foreign import explode
9foreign import explode
10+ """
10− "function explode() {\
11+ function explode() {
11− \ throw new Error('Incorrect result');\
12+ throw new Error('Incorrect result');
13+ }
12− \}" :: forall eff a. Eff eff a
14+ """ :: forall eff a. Eff eff a
13
15
14main = case match2 [1, 2, 3, 4, 5, 6, 7, 8, 9] of
16main = case match2 [1, 2, 3, 4, 5, 6, 7, 8, 9] of
15 100 -> Debug.Trace.trace "Done"
17 100 -> Debug.Trace.trace "Done"
examples/passing/EmptyDataDecls.purs+12−8
@@ -11,19 +11,23 @@ nil :: forall a. ArrayBox Z a
11nil = ArrayBox []
11nil = ArrayBox []
12
12
13foreign import concat
13foreign import concat
14+ """
14− "function concat(l1) {\
15+ function concat(l1) {
15− \ return function (l2) {\
16+ return function(l2) {
16− \ return l1.concat(l2);\
17+ return l1.concat(l2);
17− \ };\
18+ };
19+ }
18− \}" :: forall a. [a] -> [a] -> [a]
20+ """ :: forall a. [a] -> [a] -> [a]
19
21
20cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
22cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
21cons' x (ArrayBox xs) = ArrayBox $ concat [x] xs
23cons' x (ArrayBox xs) = ArrayBox $ concat [x] xs
22
24
23foreign import error
25foreign import error
26+ """
24− "function error(msg) {\
27+ function error(msg) {
25− \ throw msg;\
28+ throw msg;
29+ }
26− \}" :: forall a. String -> a
30+ """ :: forall a. String -> a
27
31
28main = case cons' 1 $ cons' 2 $ cons' 3 nil of
32main = case cons' 1 $ cons' 2 $ cons' 3 nil of
29 ArrayBox [1, 2, 3] -> Debug.Trace.trace "Done"
33 ArrayBox [1, 2, 3] -> Debug.Trace.trace "Done"
examples/passing/ExternRaw.purs+20−7
@@ -1,13 +1,26 @@
1module Main where
1module Main where
2
2
3−foreign import first "function first(xs) { return xs[0]; }" :: forall a. [a] -> a
3+foreign import first
4+ """
5+ function first(xs) {
6+ return xs[0];
7+ }
8+ """ :: forall a. [a] -> a
4
9
5−foreign import loop "function loop() { while (true) {} }" :: forall a. a
10+foreign import loop
11+ """
12+ function loop() {
13+ while (true) {}
14+ }
15+ """ :: forall a. a
6
16
7−foreign import concat "function concat(xs) { \
17+foreign import concat
18+ """
19+ function concat(xs) {
8− \ return function(ys) { \
20+ return function(ys) {
9− \ return xs.concat(ys); \
21+ return xs.concat(ys);
10− \ };\
22+ };
23+ }
11− \}" :: forall a. [a] -> [a] -> [a]
24+ """ :: forall a. [a] -> [a] -> [a]
12
25
13main = Debug.Trace.trace "Done"
26main = Debug.Trace.trace "Done"
examples/passing/FFI.purs+5−3
@@ -1,9 +1,11 @@
1module Main where
1module Main where
2
2
3foreign import foo
3foreign import foo
4+ """
4− "function foo(s) {\
5+ function foo(s) {
5− \ return s;\
6+ return s;
7+ }
6− \}" :: String -> String
8+ """ :: String -> String
7
9
8bar :: String -> String
10bar :: String -> String
9bar _ = foo "test"
11bar _ = foo "test"
examples/passing/FunctionScope.purs+5−3
@@ -6,9 +6,11 @@ module Main where
6 mkValue id = id
6 mkValue id = id
7
7
8 foreign import error
8 foreign import error
9+ """
9− "function error(msg) {\
10+ function error(msg) {
10− \ throw msg;\
11+ throw msg;
12+ }
11− \}" :: forall a. String -> a
13+ """ :: forall a. String -> a
12
14
13 main = do
15 main = do
14 let value = mkValue 1
16 let value = mkValue 1
examples/passing/Functions2.purs+5−3
@@ -6,9 +6,11 @@ module Main where
6 test = \const _ -> const
6 test = \const _ -> const
7
7
8 foreign import error
8 foreign import error
9+ """
9− "function error(msg) {\
10+ function error(msg) {
10− \ throw msg;\
11+ throw msg;
12+ }
11− \}" :: forall a. String -> a
13+ """ :: forall a. String -> a
12
14
13 main = do
15 main = do
14 let value = test "Done" {}
16 let value = test "Done" {}
examples/passing/HoistError.purs+7−5
@@ -4,11 +4,13 @@ import Control.Monad.Eff
4import Debug.Trace
4import Debug.Trace
5
5
6foreign import f
6foreign import f
7+ """
7− "function f(x) {\
8+ function f(x) {
8− \ return function () {\
9+ return function() {
9− \ if (x !== 0) throw new Error('x is not 0');\
10+ if (x !== 0) throw new Error('x is not 0');
11+ };
10− \ }\
12+ }
11− \}" :: forall e. Number -> Eff e Number
13+ """ :: forall e. Number -> Eff e Number
12
14
13main = do
15main = do
14 let x = 0
16 let x = 0
examples/passing/OperatorAssociativity.purs+15−9
@@ -6,20 +6,26 @@ import Debug.Trace
6foreign import data Assert :: !
6foreign import data Assert :: !
7
7
8foreign import assert
8foreign import assert
9+ """
10+ function assert(x) {
9− "function assert(x) { return function (desc) {\
11+ return function(desc) {
10− \ return function () {\
12+ return function() {
11− \ if (!x) throw new Error('assertion (' + desc + ') failed');\
13+ if (!x) throw new Error('assertion (' + desc + ') failed');
12− \ return {};\
14+ return {};
13− \ };\
15+ };
16+ };
17+ }
14− \};};" :: forall e. Boolean -> String -> Eff (assert :: Assert | e) Unit
18+ """ :: forall e. Boolean -> String -> Eff (assert :: Assert | e) Unit
15
19
16bug :: Number -> Number -> Number
20bug :: Number -> Number -> Number
17bug a b = 0 - (a - b)
21bug a b = 0 - (a - b)
18
22
19foreign import explode
23foreign import explode
24+ """
20− "function explode() {\
25+ function explode() {
21− \ throw new Error('Assertion failed!');\
26+ throw new Error('Assertion failed!');
27+ }
22− \}":: forall eff a. Eff eff a
28+ """ :: forall eff a. Eff eff a
23
29
24main = do
30main = do
25 assert (bug 0 2 == 2) "bug 0 2 == 2"
31 assert (bug 0 2 == 2) "bug 0 2 == 2"
examples/passing/PartialFunction.purs+10−8
@@ -1,14 +1,16 @@
1module Main where
1module Main where
2
2
3foreign import testError
3foreign import testError
4+ """
4− "function testError(f) {\
5+ function testError(f) {
5− \ try {\
6+ try {
6− \ return f();\
7+ return f();
7− \ } catch (e) {\
8+ } catch (e) {
8− \ if (e instanceof Error) return 'success';\
9+ if (e instanceof Error) return 'success';
9− \ throw new Error('Pattern match failure is not Error');\
10+ throw new Error('Pattern match failure is not Error');
10− \ }\
11+ }
12+ }
11− \}" :: (Unit -> Number) -> String
13+ """ :: (Unit -> Number) -> String
12
14
13fn :: Number -> Number
15fn :: Number -> Number
14fn 0 = 0
16fn 0 = 0
examples/passing/Person.purs+5−3
@@ -5,9 +5,11 @@ module Main where
5 data Person = Person { name :: String, age :: Number }
5 data Person = Person { name :: String, age :: Number }
6
6
7 foreign import itoa
7 foreign import itoa
8+ """
8− "function itoa(n) {\
9+ function itoa(n) {
9− \ return n.toString();\
10+ return n.toString();
11+ }
10− \}" :: Number -> String
12+ """ :: Number -> String
11
13
12 showPerson :: Person -> String
14 showPerson :: Person -> String
13 showPerson = \p -> case p of
15 showPerson = \p -> case p of
examples/passing/ShadowedRename.purs+7−5
@@ -4,11 +4,13 @@ import Control.Monad.Eff
4import Debug.Trace
4import Debug.Trace
5
5
6foreign import f
6foreign import f
7+ """
7− "function f(x) {\
8+ function f(x) {
8− \ return function () {\
9+ return function() {
9− \ if (x !== 2) throw new Error('x is not 2');\
10+ if (x !== 2) throw new Error('x is not 2');
11+ };
10− \ }\
12+ }
11− \}" :: forall e. Number -> Eff e Number
13+ """ :: forall e. Number -> Eff e Number
12
14
13foo foo = let foo_1 = \_ -> foo
15foo foo = let foo_1 = \_ -> foo
14 foo_2 = foo_1 unit + 1
16 foo_2 = foo_1 unit + 1