git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update docs for multiple argument functions
65e05dcPhil Freeman
docs/source/blocks.rst+4−4
@@ -1,7 +1,7 @@
1Blocks
1Blocks
2======
2======
3
3
4−Blocks are collections of statements wrapped in braces `{ ... }`. Blocks must return a value of the same type on every branch of execution.
4+Blocks are collections of statements wrapped in braces ``{ ... }``. Blocks must return a value of the same type on every branch of execution.
5
5
6The following types of statement are supported:
6The following types of statement are supported:
7
7
@@ -30,7 +30,7 @@ That is, while the example above is valid, the following does not compile::
30 return n;
30 return n;
31 }
31 }
32
32
33−The variable `n` is not mutable, and so the assignment in the first line of the `do` block is not allowed.
33+The variable ``n`` is not mutable, and so the assignment in the first line of the block is not allowed.
34
34
35This function can be rewritten as follows::
35This function can be rewritten as follows::
36
36
@@ -58,7 +58,7 @@ The bounds `0` and `10` are inclusive and exclusive respectively.
58While Loops
58While Loops
59------------
59------------
60
60
61−While loops repeat a set of statements while a boolean expression evaluates to `true`::
61+While loops repeat a set of statements while a boolean expression evaluates to ``true``::
62
62
63 log2 n = {
63 log2 n = {
64 var count = 0;
64 var count = 0;
@@ -73,7 +73,7 @@ While loops repeat a set of statements while a boolean expression evaluates to `
73If-Then-Else Statements
73If-Then-Else Statements
74-----------------------
74-----------------------
75
75
76−Else branches are optional, and may contain further `if` statements, just as in Javascript:
76+Else branches are optional, and may contain further ``if`` statements, just as in Javascript:
77
77
78 collatz n = {
78 collatz n = {
79 var count = 0;
79 var count = 0;
docs/source/intro.rst−1
@@ -9,7 +9,6 @@ PureScript is a small strongly, statically typed compile-to-JS language with a n
9- Extensible records
9- Extensible records
10- Extensible effects
10- Extensible effects
11- Type-safe blocks with for/while/assignment etc.
11- Type-safe blocks with for/while/assignment etc.
12−- Functions with multiple arguments
13- Pattern matching
12- Pattern matching
14- Simple FFI
13- Simple FFI
15- Modules
14- Modules
docs/source/modules.rst+2−2
@@ -1,7 +1,7 @@
1Modules
1Modules
2=======
2=======
3
3
4−All code in PureScript is contained in a module. Modules are introduced using the `module` keyword::
4+All code in PureScript is contained in a module. Modules are introduced using the ``module`` keyword::
5
5
6 module A where
6 module A where
7
7
@@ -16,7 +16,7 @@ When referencing values or data types in another module, names may be qualified
16Importing Modules
16Importing Modules
17-----------------
17-----------------
18
18
19−A module can be imported using the `import` keyword. This will create aliases for all of the values and types in the imported module::
19+A module can be imported using the ``import`` keyword. This will create aliases for all of the values and types in the imported module::
20
20
21 module B where
21 module B where
22
22
docs/source/patterns.rst+29−41
@@ -14,9 +14,9 @@ Pattern matching can also be used in the declaration of functions, as we have al
14
14
15 fn pattern_1 ... pattern_n = result
15 fn pattern_1 ... pattern_n = result
16
16
17−Any of the above types of pattern are also valid when introducing functions. In addition, patterns can also be grouped in parentheses to introduce multiple-arugument functions. For example::
17+Patterns can also be used when introducing functions. For example::
18
18
19− example x (y, z) w = x * y + z * w
19+ example x y z = x * y + z
20
20
21The following pattern types are supported:
21The following pattern types are supported:
22
22
@@ -36,43 +36,37 @@ Wildcard Patterns
36
36
37The wilcard `_` matches any input and brings nothing into scope::
37The wilcard `_` matches any input and brings nothing into scope::
38
38
39− case x of
40− _ -> 0
39+ f _ = 0
41
40
42Literal Patterns
41Literal Patterns
43----------------
42----------------
44
43
45Literal patterns are provided to match on primitives::
44Literal patterns are provided to match on primitives::
46
45
47− case booleanValue of
48− true -> 0
46+ f true = 0
49− false -> 1
47+ f false = 1
50
48
51− case stringValue of
52− "Foo" -> 0
49+ g "Foo" = 0
53− _ -> 1
50+ g _ = 1
54
51
55− case numericValue of
56− 0 -> 0
52+ h 0 = 0
57− _ -> 1
53+ h _ = 1
58
54
59Variable Patterns
55Variable Patterns
60-----------------
56-----------------
61
57
62A variable pattern matches any input and binds that input to its name::
58A variable pattern matches any input and binds that input to its name::
63
59
64− case foo(x) of
60+ double x = x * 2
65− result -> bar(result)
66
61
67Array Patterns
62Array Patterns
68--------------
63--------------
69
64
70Array patterns match an input which is an array, and bring its elements into scope. For example::
65Array patterns match an input which is an array, and bring its elements into scope. For example::
71
66
72− f = \arr -> case arr of
73− [x] -> x
67+ f [x] = x
74− [x, y] -> x * y + f xs
68+ f [x, y] = x * y + f xs
75− _ -> 0
69+ f _ = 0
76
70
77Here, the first pattern only matches arrays of length one, and brings the first element of the array into scope.
71Here, the first pattern only matches arrays of length one, and brings the first element of the array into scope.
78
72
@@ -83,55 +77,49 @@ Cons Patterns
83
77
84The head and tail of a non-empty array can be matched by using a cons pattern::
78The head and tail of a non-empty array can be matched by using a cons pattern::
85
79
86− add = \arr -> case arr of
87− [] -> 0
80+ sum [] = 0
88− x : xs -> x + add xs
81+ sum (x : xs) = x + sum xs
89
82
90`:` associates to the right::
83`:` associates to the right::
91
84
92− addPairs = \arr -> case arr of
93− x : y : xs -> x * y + addPairs xs
85+ addPairs (x : y : xs) = x * y + addPairs xs
94− _ -> 0
86+ addPairs _ = 0
95
87
96Record Patterns
88Record Patterns
97---------------
89---------------
98
90
99Record patterns match an input which is a record, and bring its properties into scope::
91Record patterns match an input which is a record, and bring its properties into scope::
100
92
101− f = \o -> case o of
102− { foo = "Foo" } -> o.bar
93+ f { foo = "Foo" } = o.bar
103− _ -> 0
94+ f _ = 0
104
95
105Nested Patterns
96Nested Patterns
106---------------
97---------------
107
98
108The patterns above can be combined to create larger patterns. For example::
99The patterns above can be combined to create larger patterns. For example::
109
100
110− f = \o -> case o of
111− { arr = x : _, take = "car" } -> x
101+ f { arr = x : _, take = "car" } = x
112− { arr = _ : x : _, take = "cadr" } -> x
102+ f { arr = _ : x : _, take = "cadr" } = x
113− _ -> 0
103+ f _ = 0
114
104
115Named Patterns
105Named Patterns
116--------------
106--------------
117
107
118−Named patterns bring additional names into scope when using nested patterns. Any pattern can be named by using the `@` symbol::
108+Named patterns bring additional names into scope when using nested patterns. Any pattern can be named by using the ``@`` symbol::
119
109
120− f = \arr -> case arr of
121− a@(_ : _ : _) -> true
110+ f a@(_ : _ : _) = true
122− a -> false
111+ f _ = false
123
112
124−Here, in the first pattern, any array with two or more elements will be matched and bound to the variable `a`.
113+Here, in the first pattern, any array with two or more elements will be matched and bound to the variable ``a``.
125
114
126Guards
115Guards
127------
116------
128
117
129Guards are used to impose additional constraints inside a pattern using boolean-valued expressions, and are introduced with a pipe after the pattern::
118Guards are used to impose additional constraints inside a pattern using boolean-valued expressions, and are introduced with a pipe after the pattern::
130
119
131− evens = \arr -> case arr of
120+ evens [] = 0
132− [] -> 0
133− x : xs | x % 2 == 0 -> 1 + evens xs
121+ evens (x : xs) | x % 2 == 0 = 1 + evens xs
134− _ : xs -> evens xs
122+ evens (_ : xs) = evens xs
135
123
136When using patterns to define a function at the top level, guards appear after all patterns::
124When using patterns to define a function at the top level, guards appear after all patterns::
137
125
docs/source/syntax.rst+16−56
@@ -15,7 +15,6 @@ But this is not::
15
15
16 foo = bar(x) +
16 foo = bar(x) +
17 baz(x)
17 baz(x)
18− data UnaryOperator
19
18
20Operators
19Operators
21---------
20---------
@@ -61,7 +60,7 @@ and the following binary operators (in precedence order):
61Literal Values
60Literal Values
62--------------
61--------------
63
62
64−Numeric literals can be integers or floating point numbers. Numbers in hexadecimal notation should be preceded by the characters `0x`::
63+Numeric literals can be integers or floating point numbers. Numbers in hexadecimal notation should be preceded by the characters ``0x``::
65
64
66 16
65 16
67 16.0
66 16.0
@@ -123,53 +122,14 @@ which would correspond to the following Javascript::
123 }
122 }
124 }
123 }
125
124
126−Multiple argument functions can be introduced by wrapping the arguments in parentheses, and separating them with commas::
125+Function application is indicated by just the juxtaposition of a function with its arugments::
127
126
128− example2 = \(a, b) -> a + b
127+ example1 10 20
129
128
130−which generates::
129+Functions can also be defined at the top level by providing a list of patterns and an optional guard on the left hand side of the equals sign::
131
130
132− function example2(a, b) {
131+ f [] [] = []
133− return a + b;
132+ f (x:xs) (y:ys) = x + y : f xs ys
134− }
135−
136−There is a special case for functions with no arguments, where the parentheses may be omitted, as follows::
137−
138− example3 = \ -> 100
139−
140−which would correspond to the Javascript::
141−
142− function example3() {
143− return 100;
144− }
145−
146−Multiple-argument and single-argument syntax can be mixed, as follows::
147−
148− example4 = \a (b, c) d -> a + b + c + d
149−
150−which generates::
151−
152− function example4(a) {
153− return function (b, c) {
154− return function (d) {
155− return a + b + c + d;
156− }
157− }
158− }
159−
160−Functions are applied by providing their arguments inside parentheses::
161−
162− test1(1, 2, 3)
163− test2()
164−
165−A special case is made in the case of functions with one argument. These functions can be applied without parentheses, and function application associates to the left::
166−
167− addThree :: Number -> Number -> Number -> Number
168− addThree a b c = a + b + c
169−
170− addThree 1 :: Number -> Number -> Number
171− addThree 1 2 :: Number -> Number
172− addThree 1 2 3 :: Number
173
133
174If-Then-Else Expressions
134If-Then-Else Expressions
175------------------------
135------------------------
@@ -204,23 +164,23 @@ Here is an example, using the maybe monad::
204 isEven sum
164 isEven sum
205 ret sum
165 ret sum
206
166
207−`isEven` adds two values of type `Maybe Number` and returns their sum, if the sum is even. If the sum is odd, `evenSum` returns `Nothing`.
167+``isEven`` adds two values of type ``Maybe Number`` and returns their sum, if the sum is even. If the sum is odd, ``evenSum`` returns ``Nothing``.
208
168
209−When using `do` notation, the corresponding type constructor must be an instance of the `Prelude.Monad` type class, which defines the `ret` and `>>=` functions.
169+When using `do` notation, the corresponding type constructor must be an instance of the `Prelude.Monad` type class, which defines the ``ret`` and ``>>=`` functions.
210
170
211Statements can have the following form:
171Statements can have the following form:
212
172
213−- `a <- x` which desugars to `m.bind x (\a -> ...)`
173+- ``a <- x`` which desugars to ``m.bind x (\a -> ...)` `
214−- `let a = x` which desugars to `(\a -> ...)(x)`
174+- ``let a = x`` which desugars to ``(\a -> ...)(x)``
215−- `x` which desugars to `m.bind x (\_ -> ...)` or just `x` if this is the last statement.
175+- ``x`` which desugars to ``m.bind x (\_ -> ...)`` or just ``x`` if this is the last statement.
216
176
217−Binders can be used on the left hand side of `<-` or `=`. For example::
177+Binders can be used on the left hand side of ``<-`` or ``=``. For example::
218
178
219 test arr = do
179 test arr = do
220 (x:y:_) <- arr
180 (x:y:_) <- arr
221 ret (x + y)
181 ret (x + y)
222
182
223−A pattern match failure will generate a runtime exception, just as in the case of a regular `case` statement.
183+A pattern match failure will generate a runtime exception, just as in the case of a regular ``case`` statement.
224
184
225Operators
185Operators
226---------
186---------
@@ -251,11 +211,11 @@ Properties on records can be updated using the following syntax::
251
211
252 o { key = value, ..., key = value }
212 o { key = value, ..., key = value }
253
213
254−For example, the following function increments the `foo` property on its argument::
214+For example, the following function increments the ``foo`` property on its argument::
255
215
256− incr = \o -> o { foo = o.foo + 1 }
216+ incr o = o { foo = o.foo + 1 }
257
217
258−The generated Javascript assumes the existence of a method called `Object.extend` such that `Object.extend(o, p)` takes an object `o` and generates a shallow copy of `o` including the properties of `p`. A simple JQuery implementation of this specification is::
218+The generated Javascript assumes the existence of a method called ``Object.extend`` such that ``Object.extend(o, p)`` takes an object ``o`` and generates a shallow copy of ``o`` including the properties of ``p``. A simple JQuery implementation of this specification is::
259
219
260 Object.prototype.extend = function(o, p) {
220 Object.prototype.extend = function(o, p) {
261 return $.extend({}, o, p);
221 return $.extend({}, o, p);
docs/source/types.rst+1−1
@@ -51,7 +51,7 @@ In the example, Foo is a tagged union type which has two constructors. It's firs
51Functions
51Functions
52---------
52---------
53
53
54−Functions in PureScript can have zero or more arguments. A function with multiple arguments is not to be confused with a `curried function`, which takes a single argument, and returns another function.
54+Functions in PureScript are like their Javascript counterparts, but always have exactly one argument.
55
55
56Polymorphic Types
56Polymorphic Types
57-----------------
57-----------------