git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update docs, add more examples
4bb6219Phil Freeman
docs/source/intro.rst+2−2
@@ -112,11 +112,11 @@ Line by line, this reads as follows:
112The generated Javascript looks like this::
112The generated Javascript looks like this::
113
113
114 var Person = function (value) {
114 var Person = function (value) {
115− return { ctor: 'Person', value: value };
115+ return { ctor: 'Person', values: [value] };
116 };
116 };
117
117
118 function showPerson(_1) {
118 function showPerson(_1) {
119− return _1.value.name + ", aged " + numberToString(_1.value.age);
119+ return _1.values[0].name + ", aged " + numberToString(_1.values[0].age);
120 };
120 };
121
121
122Related Projects
122Related Projects
docs/source/patterns.rst+12
@@ -25,6 +25,7 @@ The following pattern types are supported:
25- Variable pattern
25- Variable pattern
26- Array patterns
26- Array patterns
27- Cons patterns
27- Cons patterns
28+- Constructor patterns
28- Record patterns
29- Record patterns
29- Named patterns
30- Named patterns
30- Guards
31- Guards
@@ -85,6 +86,17 @@ The head and tail of a non-empty array can be matched by using a cons pattern::
85 addPairs (x : y : xs) = x * y + addPairs xs
86 addPairs (x : y : xs) = x * y + addPairs xs
86 addPairs _ = 0
87 addPairs _ = 0
87
88
89+
90+Constructor patterns
91+--------------------
92+
93+Constructor patterns match a data constructor and its arguments::
94+
95+ data Foo = Foo String | Bar Number Boolean
96+
97+ foo (Foo s) = true
98+ foo (Bar _ b) = b
99+
88Record Patterns
100Record Patterns
89---------------
101---------------
90
102
docs/source/types.rst+1−1
@@ -31,7 +31,7 @@ PureScript records correspond to Javascript objects. They may have zero or more
31Tagged Unions
31Tagged Unions
32-------------
32-------------
33
33
34−Tagged unions consist of one or more constructors, each of which takes zero or one arguments.
34+Tagged unions consist of one or more constructors, each of which takes zero or more arguments.
35
35
36Tagged unions can only be created using their constructors, and deconstructed through pattern matching (see later).
36Tagged unions can only be created using their constructors, and deconstructed through pattern matching (see later).
37
37
examples/passing/MultipleConstructorArgs.purs+15−1
@@ -1,14 +1,28 @@
1module MultipleConstructorArgs where
1module MultipleConstructorArgs where
2
2
3+import Arrays
4+
3data P a b = P a b
5data P a b = P a b
4
6
5runP :: forall a b r. (a -> b -> r) -> P a b -> r
7runP :: forall a b r. (a -> b -> r) -> P a b -> r
6runP f (P a b) = f a b
8runP f (P a b) = f a b
7
9
10+idP = runP P
11+
12+testCase = \p -> case p of
13+ P (x:xs) (y:ys) -> x : y : testCase (P xs ys)
14+ P _ _ -> []
15+
16+test1 = testCase (P [1, 2, 3] [4, 5, 6])
17+
8module Main where
18module Main where
9
19
10import Prelude
20import Prelude
11import MultipleConstructorArgs
21import MultipleConstructorArgs
12import Global
22import Global
23+import Eff
24+import Arrays
13
25
26+main = do
14−main = Trace.trace (runP (\s n -> s ++ show n) (P "Test" 1))
27+ Trace.trace (runP (\s n -> s ++ show n) (P "Test" 1))
28+ Trace.print test1