git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update README.md
a543c4ePhil Freeman
README.md+33−33
@@ -61,11 +61,11 @@ The following code defines a `Person` data type and a function to generate a str
61 , age :: Number
61 , age :: Number
62 }
62 }
63
63
64− extern itoa :: Number -> String
64+ extern itoa :: Number -> String
65
65
66− showPerson :: Person -> String
66+ showPerson :: Person -> String
67− showPerson = \p -> case p of
67+ showPerson = \p -> case p of
68− Person o -> o.name ++ ", aged " ++ itoa(o.age)
68+ Person o -> o.name ++ ", aged " ++ itoa(o.age)
69
69
70Line by line, this reads as follows:
70Line by line, this reads as follows:
71
71
@@ -77,20 +77,20 @@ Line by line, this reads as follows:
77
77
78The generated Javascript looks like this:
78The generated Javascript looks like this:
79
79
80− var Person = function (value) {
80+ var Person = function (value) {
81− return { ctor: 'Person', value: value };
81+ return { ctor: 'Person', value: value };
82− };
82+ };
83+
83− var showPerson = function (p) {
84+ var showPerson = function (p) {
84− return (function (_0) {
85+ return (function (_0) {
85− if (_0.ctor === "Person") {
86+ if (_0.ctor === "Person") {
86− var _1 = _0.value;
87+ var _1 = _0.value;
87− var o = _1;
88+ var o = _1;
88− return o.name ++ ", aged "
89+ return o.name ++ ", aged " ++ itoa(o.age);
89− ++ itoa(o.age);
90− }
90+ }
91− throw "Failed pattern match";
91+ throw "Failed pattern match";
92− })(p);
92+ })(p);
93− };
93+ };
94
94
95## Type System
95## Type System
96
96
@@ -291,17 +291,17 @@ This function can be rewritten as follows:
291
291
292 incr = \n -> do
292 incr = \n -> do
293 var m = n
293 var m = n
294− m = m + 1
294+ m = m + 1
295− return m
295+ return m
296
296
297Object properties and array elements can also be mutated inside a block. For example:
297Object properties and array elements can also be mutated inside a block. For example:
298
298
299 createObject = do
299 createObject = do
300− var a = [1, 2, 3]
300+ var a = [1, 2, 3]
301− a[1] = 4
301+ a[1] = 4
302− var o = { foo: [] }
302+ var o = { foo: [] }
303− o.foo = a
303+ o.foo = a
304− return o
304+ return o
305
305
306## For loops
306## For loops
307
307
@@ -414,7 +414,7 @@ For example:
414 f = \arr -> case arr of
414 f = \arr -> case arr of
415 [x] -> x
415 [x] -> x
416 [x, y : xs] -> x * y + f(xs)
416 [x, y : xs] -> x * y + f(xs)
417− _ -> 0
417+ _ -> 0
418
418
419Here, the first pattern only matches arrays of length one, and brings the first element of the array into scope.
419Here, the first pattern only matches arrays of length one, and brings the first element of the array into scope.
420
420
@@ -426,7 +426,7 @@ Record patterns match an input which is a record, and bring its properties into
426
426
427 f = \o -> case o of
427 f = \o -> case o of
428 { foo = "Foo" } -> o.bar
428 { foo = "Foo" } -> o.bar
429− _ -> 0
429+ _ -> 0
430
430
431## Nested Patterns
431## Nested Patterns
432
432
@@ -466,7 +466,7 @@ E.g. to create a synonym for string concatenation:
466
466
467 (<>) = \s1 -> \s2 -> s1 ++ s2
467 (<>) = \s1 -> \s2 -> s1 ++ s2
468
468
469− "Hello" <> "World!"
469+ greeting = "Hello" <> "World!"
470
470
471Regular functions can be used as operators by enclosing their names in backticks:
471Regular functions can be used as operators by enclosing their names in backticks:
472
472
@@ -483,12 +483,12 @@ Fixity declarations can associate a precedence level, which is a natural number,
483
483
484The `extern` keyword declares a value which is defined in Javascript, and its type:
484The `extern` keyword declares a value which is defined in Javascript, and its type:
485
485
486− extern pow :: (Number, Number) -> Number
486+ extern pow :: (Number, Number) -> Number
487
487
488To declare a new type with no constructors, use `extern data` and provide the kind:
488To declare a new type with no constructors, use `extern data` and provide the kind:
489
489
490− extern IO :: * -> *
490+ extern IO :: * -> *
491
491
492− extern console :: {
492+ extern console :: {
493− log :: String -> IO {}
493+ log :: String -> IO {}
494− }
494+ }