@@ -1,231 +1,107 @@
3−Syntax is whitespace sensitive. The general rule of thumb is that declarations which span multiple lines should be indented past the column on which they were first defined on their subsequent lines.
4+Whitespace Rules
5−That is, the following is valid:
21−Blocks are collections of statements wrapped in braces `{ ... }`. Blocks must return a value of the same type on every branch of execution.
23−The following types of statement are supported:
25−- Variable introduction
30−- If-Then-Else statements
32−Here is an example of a power function defined using a block:
37− for (i <- 0 until p) {
44−Blocks enable local mutation of their variables, but mutation is not allowed in general. The type system prevents mutable variables from escaping their scope.
46−That is, while the example above is valid, the following does not compile:
48−```haskell
7+Syntax is whitespace sensitive. The general rule of thumb is that declarations which span multiple lines should be indented past the column on which they were first defined on their subsequent lines.
55−The variable `n` is not mutable, and so the assignment in the first line of the `do` block is not allowed.
57−This function can be rewritten as follows:
67−## For Loops
9+That is, the following is valid::
69−For loops look like this:
11+ foo = bar(x) +
71−```haskell
14+But this is not::
74− for (i <- 0 until 10) {
81−The bounds `0` and `10` are inclusive and exclusive respectively.
16+ foo = bar(x) +
85−For each loops loop over the elements in an array using the `Object.forEach` method. A polyfill may be required for some browsers:
99−The syntax of a while loop is similar to a foreach loop:
113−## If-Then-Else Statements
115−Else branches are optional, and may contain further `if` statements, just as in Javascript:
133−## If-Then-Else Expressions
19+If-Then-Else Expressions
20+------------------------
135−The `if`, `then` and `else` keywords can also be used to create conditional expressions. In this case, the `else` block is always required.
22+The `if`, `then` and `else` keywords can be used to create conditional expressions. In this case, the `else` block is always required.
137−For example,
24+For example::
140−conditional = if 2 > 1 then "ok" else "oops"
26+ conditional = if 2 > 1 then "ok" else "oops"
143−## Do Notation
28+Do Notation
145The `do` keyword introduces simple syntactic sugar for monadic expressions.
31The `do` keyword introduces simple syntactic sugar for monadic expressions.
147−Here is an example, using the maybe monad:
33+Here is an example, using the maybe monad::
150−data Maybe a = Nothing | Just a
35+ data Maybe a = Nothing | Just a
152−instance Monad Maybe where
37+ instance Monad Maybe where
153− ret = Just
38+ ret = Just
154− (>>=) Nothing _ = Nothing
39+ (>>=) Nothing _ = Nothing
155− (>>=) (Just a) f = f a
40+ (>>=) (Just a) f = f a
157−isEven n | n % 2 == 0 = Just {}
42+ isEven n | n % 2 == 0 = Just {}
158−isEven _ = Nothing
43+ isEven _ = Nothing
160−evenSum a b = do
45+ evenSum a b = do
163− let sum = n + m
48+ let sum = n + m
164− isEven sum
49+ isEven sum
168`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`.
52`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`.
170−This example illustrates the following aspects of `do` notation:
54+When using `do` notation, the corresponding type constructor must be an instance of the `Prelude.Monad` type class, which defines the `ret` and `>>=` functions.
172−- The corresponding type constructor must be an instance of the `Prelude.Monad` type class, which defines the `ret` and `>>=` functions.
173−- Statements can have the following form:
56+Statements can have the following form:
174− - `a <- x` which desugars to `m.bind x (\a -> ...)`
175− - `let a = x` which desugars to `(\a -> ...)(x)`
176− - `x` which desugars to `m.bind x (\_ -> ...)` or just `x` if this is the last statement.
178−Not illustrated here, but equally valid is the use of a binder on the left hand side of `<-` or `=`. For example:
58+- `a <- x` which desugars to `m.bind x (\a -> ...)`
59+- `let a = x` which desugars to `(\a -> ...)(x)`
60+- `x` which desugars to `m.bind x (\_ -> ...)` or just `x` if this is the last statement.
180−```haskell
62+Binders can be used on the left hand side of `<-` or `=`. For example::
186−A pattern match failure will generate a runtime exception, just as in the case of a regular `case` statement.
64+ test arr = do
188−## Operators
68+A pattern match failure will generate a runtime exception, just as in the case of a regular `case` statement.
190−In addition to the standard operators, user-defined infix operators can be created by enclosing names in parentheses:
192−E.g. to create a synonym for string concatenation:
70+Operators
194−```haskell
73+In addition to the standard operators, user-defined infix operators can be created by enclosing names in parentheses.
195−(<>) = \s1 s2 -> s1 ++ s2
197−greeting = "Hello" <> "World!"
75+E.g. to create a synonym for string concatenation::
200−Regular functions can be used as operators by enclosing their names in backticks:
77+ (<>) = \s1 s2 -> s1 ++ s2
79+ greeting = "Hello" <> "World!"
202−```haskell
81+Regular functions can be used as operators by enclosing their names in backticks::
203−foo = \x y -> x * y + y
83+ foo = \x y -> x * y + y
205−test = 10 `foo` 20
85+ test = 10 `foo` 20
208−Fixity declarations can associate a precedence level, which is a natural number, to a user-defined operator, and specify which way it associates:
87+Fixity declarations can associate a precedence level, which is a natural number, to a user-defined operator, and specify which way it associates::
210−```haskell
92+Record Updates
211−infixl 5 <>
93+--------------
215−## Record Updates
95+Properties on records can be updated using the following syntax::
217−Properties on records can be updated using the following syntax: `o { key = value, ..., key = value }`
97+ o { key = value, ..., key = value }
219−For example, the following function increments the `foo` property on its argument:
99+For example, the following function increments the `foo` property on its argument::
222−incr = \o -> o { foo = o.foo + 1 }
101+ incr = \o -> o { foo = o.foo + 1 }
225−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
103+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::
228Object.prototype.extend = function(o, p) {
105Object.prototype.extend = function(o, p) {
229 return $.extend({}, o, p);
106 return $.extend({}, o, p);