git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update README.md
commita543c4e308eb3571a98a2ebd4241108e6f398b66 authorPhil Freeman <paf31@cantab.net> dateWed 30 Oct 2013, 12:24 (13 years ago) parent3c03db3
1 file changed+33−33
README.md+33−33
README.md+33−33
@@ -61,11 +61,11 @@ The following code defines a `Person` data type and a function to generate a str
6161 , age :: Number
6262 }
6363
64− extern itoa :: Number -> String
64+ extern itoa :: Number -> String
6565
66− showPerson :: Person -> String
67− showPerson = \p -> case p of
68− Person o -> o.name ++ ", aged " ++ itoa(o.age)
66+ showPerson :: Person -> String
67+ showPerson = \p -> case p of
68+ Person o -> o.name ++ ", aged " ++ itoa(o.age)
6969
7070Line by line, this reads as follows:
7171
@@ -77,20 +77,20 @@ Line by line, this reads as follows:
7777
7878The generated Javascript looks like this:
7979
80− var Person = function (value) {
81− return { ctor: 'Person', value: value };
82− };
83− var showPerson = function (p) {
84− return (function (_0) {
85− if (_0.ctor === "Person") {
86− var _1 = _0.value;
87− var o = _1;
88− return o.name ++ ", aged "
89− ++ itoa(o.age);
90− }
91− throw "Failed pattern match";
92− })(p);
93− };
80+ var Person = function (value) {
81+ return { ctor: 'Person', value: value };
82+ };
83+
84+ var showPerson = function (p) {
85+ return (function (_0) {
86+ if (_0.ctor === "Person") {
87+ var _1 = _0.value;
88+ var o = _1;
89+ return o.name ++ ", aged " ++ itoa(o.age);
90+ }
91+ throw "Failed pattern match";
92+ })(p);
93+ };
9494
9595## Type System
9696
@@ -291,17 +291,17 @@ This function can be rewritten as follows:
291291
292292 incr = \n -> do
293293 var m = n
294− m = m + 1
295− return m
294+ m = m + 1
295+ return m
296296
297297Object properties and array elements can also be mutated inside a block. For example:
298298
299299 createObject = do
300− var a = [1, 2, 3]
301− a[1] = 4
302− var o = { foo: [] }
303− o.foo = a
304− return o
300+ var a = [1, 2, 3]
301+ a[1] = 4
302+ var o = { foo: [] }
303+ o.foo = a
304+ return o
305305
306306## For loops
307307
@@ -414,7 +414,7 @@ For example:
414414 f = \arr -> case arr of
415415 [x] -> x
416416 [x, y : xs] -> x * y + f(xs)
417− _ -> 0
417+ _ -> 0
418418
419419Here, the first pattern only matches arrays of length one, and brings the first element of the array into scope.
420420
@@ -426,7 +426,7 @@ Record patterns match an input which is a record, and bring its properties into
426426
427427 f = \o -> case o of
428428 { foo = "Foo" } -> o.bar
429− _ -> 0
429+ _ -> 0
430430
431431## Nested Patterns
432432
@@ -466,7 +466,7 @@ E.g. to create a synonym for string concatenation:
466466
467467 (<>) = \s1 -> \s2 -> s1 ++ s2
468468
469− "Hello" <> "World!"
469+ greeting = "Hello" <> "World!"
470470
471471Regular functions can be used as operators by enclosing their names in backticks:
472472
@@ -483,12 +483,12 @@ Fixity declarations can associate a precedence level, which is a natural number,
483483
484484The `extern` keyword declares a value which is defined in Javascript, and its type:
485485
486− extern pow :: (Number, Number) -> Number
486+ extern pow :: (Number, Number) -> Number
487487
488488To declare a new type with no constructors, use `extern data` and provide the kind:
489489
490− extern IO :: * -> *
490+ extern IO :: * -> *
491491
492− extern console :: {
493− log :: String -> IO {}
494− }
492+ extern console :: {
493+ log :: String -> IO {}
494+ }