@@ -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
64− extern itoa :: Number -> String
64+ extern itoa :: Number -> String
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)
70Line by line, this reads as follows:
70Line by line, this reads as follows:
@@ -77,20 +77,20 @@ Line by line, this reads as follows:
78The generated Javascript looks like this:
78The generated Javascript looks like this:
80− var Person = function (value) {
80+ var Person = function (value) {
81− return { ctor: 'Person', value: value };
81+ return { ctor: 'Person', value: value };
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);
91− throw "Failed pattern match";
91+ throw "Failed pattern match";
95## Type System
95## Type System
@@ -291,17 +291,17 @@ This function can be rewritten as follows:
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
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:
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
306## For loops
306## For loops
@@ -414,7 +414,7 @@ For example:
414 f = \arr -> case arr of
414 f = \arr -> case arr of
416 [x, y : xs] -> x * y + f(xs)
416 [x, y : xs] -> x * y + f(xs)
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.
@@ -426,7 +426,7 @@ Record patterns match an input which is a record, and bring its properties into
427 f = \o -> case o of
427 f = \o -> case o of
428 { foo = "Foo" } -> o.bar
428 { foo = "Foo" } -> o.bar
431## Nested Patterns
431## Nested Patterns
@@ -466,7 +466,7 @@ E.g. to create a synonym for string concatenation:
467 (<>) = \s1 -> \s2 -> s1 ++ s2
467 (<>) = \s1 -> \s2 -> s1 ++ s2
469− "Hello" <> "World!"
469+ greeting = "Hello" <> "World!"
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:
@@ -483,12 +483,12 @@ Fixity declarations can associate a precedence level, which is a natural number,
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:
486− extern pow :: (Number, Number) -> Number
486+ extern pow :: (Number, Number) -> Number
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:
490− extern IO :: * -> *
490+ extern IO :: * -> *
492− extern console :: {
492+ extern console :: {
493− log :: String -> IO {}
493+ log :: String -> IO {}