git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update intro.rst
19064bdPhil Freeman
docs/source/intro.rst+52−75
@@ -1,5 +1,5 @@
1−purescript
1+Introduction
2−==========
2+============
3
3
4PureScript is a small strongly, statically typed compile-to-JS language with a number of interesting features, such as:
4PureScript is a small strongly, statically typed compile-to-JS language with a number of interesting features, such as:
5
5
@@ -18,45 +18,34 @@ PureScript is a small strongly, statically typed compile-to-JS language with a n
18- Optional tail-call elimination
18- Optional tail-call elimination
19- Type Classes
19- Type Classes
20
20
21−## Try It!
21+Try It!
22+-------
22
23
23Try PureScript in the browser [here](http://tryps.functorial.com/).
24Try PureScript in the browser [here](http://tryps.functorial.com/).
24
25
25−## Installation
26+Installation
27+------------
26
28
27Install the Haskell Plaform, then `cabal install`
29Install the Haskell Plaform, then `cabal install`
28
30
29−## Usage
31+Usage
32+-----
30
33
31The `psc` executable takes a list of PureScript source files as arguments and by default writes out its errors or output to the console.
34The `psc` executable takes a list of PureScript source files as arguments and by default writes out its errors or output to the console.
32
35
33The following options are supported:
36The following options are supported:
34
37
35− -s --stdin
36− Read input from standard input instead of from files
38+-s --stdin Read input from standard input instead of from files
37−
38− -o --output
39− Write the generated Javascript to the specified file
39+-o --output Write the generated Javascript to the specified file
40−
41− -e --foreign imports
42− Write a list of foreign imports declarations to the specified file in addition to generating Javascript output
40+-e --foreign imports Write a list of foreign imports declarations to the specified file in addition to generating Javascript output
43−
44− --runtime-type-checks
45− Generate simple runtime type checks for function arguments with simple types.
41+--runtime-type-checks Generate simple runtime type checks for function arguments with simple types.
46−
47− --tco
48− Perform tail-call elimination on the generated Javascript.
42+--tco Perform tail-call elimination on the generated Javascript.
49−
50− --no-prelude
51− Do not include the Prelude in the generated Javascript.
43+--no-prelude Do not include the Prelude in the generated Javascript.
52−
53− --magic-do
54− Overload the `do` keyword to inline calls to `bind` for the `Eff` monad, to generate more efficient code.
44+--magic-do Overload the `do` keyword to inline calls to `bind` for the `Eff` monad, to generate more efficient code.
55−
56− --run-main
57− Generate a call to `Main.main` after all other generated Javascript.
45+--run-main Generate a call to `Main.main` after all other generated Javascript.
58−
46+
59−## Motivation
47+Motivation
48+----------
60
49
61I was looking for a simple functional language which would compile to JavaScript and have the following characteristics:
50I was looking for a simple functional language which would compile to JavaScript and have the following characteristics:
62
51
@@ -72,46 +61,40 @@ PureScript is *not* designed to be a general-purpose programming language. The p
72
61
73PureScript can also be seen as a trade-off between a theoretically ideal language and one which generates reasonably high performance code.
62PureScript can also be seen as a trade-off between a theoretically ideal language and one which generates reasonably high performance code.
74
63
75−## Hello, PureScript!
64+Hello, PureScript!
76−
65+------------------
77−As an introductory example, here is the usual "Hello World" written in PureScript:
78−
79−```haskell
80−module Main where
81−
82−import Trace
83
66
84−main = trace "Hello, World!"
67+As an introductory example, here is the usual "Hello World" written in PureScript::
85−```
86
68
87−which compiles to the following Javascript, ignoring the Prelude:
69+ module Main where
70+
71+ import Trace
72+
73+ main = trace "Hello, World!"
88
74
89−```javascript
75+which compiles to the following Javascript, ignoring the Prelude::
90−var Main;
91−(function (Main) {
92− var main = trace("Hello, World!");
93− Main.main = main;
94−})(Main = Main || {});
95−```
96
76
97−The following command will compile and execute the PureScript code above:
77+ var Main;
78+ (function (Main) {
79+ var main = trace("Hello, World!");
80+ Main.main = main;
81+ })(Main = Main || {});
98
82
99−```
83+The following command will compile and execute the PureScript code above::
100−psc input.purs --run-main | nodejs
101−```
102
84
103−## Another Example
85+ psc input.purs --run-main | nodejs
104
86
105−The following code defines a `Person` data type and a function to generate a string representation for a `Person`:
87+Another Example
88+---------------
106
89
107−```haskell
90+The following code defines a `Person` data type and a function to generate a string representation for a `Person`::
108−data Person = Person { name :: String, age :: Number }
109
91
92+ data Person = Person { name :: String, age :: Number }
93+
110−foreign import numberToString :: Number -> String
94+ foreign import numberToString :: Number -> String
111−
95+
112−showPerson :: Person -> String
96+ showPerson :: Person -> String
113−showPerson (Person o) = o.name ++ ", aged " ++ numberToString(o.age)
97+ showPerson (Person o) = o.name ++ ", aged " ++ numberToString(o.age)
114−```
115
98
116Line by line, this reads as follows:
99Line by line, this reads as follows:
117
100
@@ -121,18 +104,12 @@ Line by line, this reads as follows:
121- The `showPerson` function takes a `Person` and returns a `String`
104- The `showPerson` function takes a `Person` and returns a `String`
122- `showPerson` works by case analysis on its argument, first matching the constructor `Person` and then using string concatenation and object accessors to return its result.
105- `showPerson` works by case analysis on its argument, first matching the constructor `Person` and then using string concatenation and object accessors to return its result.
123
106
124−The generated Javascript looks like this:
107+The generated Javascript looks like this::
125−
126−```javascript
127−var Person = function (value) {
128− return { ctor: 'Person', value: value };
129−};
130−
131−function showPerson(_1) {
132− if (_1.ctor === "Person") {
133− return _1.value.name + ", aged " + numberToString(_1.value.age);
134− };
135− throw "Failed pattern match";
136−};
137
108
138−```
109+ var Person = function (value) {
110+ return { ctor: 'Person', value: value };
111+ };
112+
113+ function showPerson(_1) {
114+ return _1.value.name + ", aged " + numberToString(_1.value.age);
115+ };