@@ -0,0 +1,138 @@
4+PureScript is a small strongly, statically typed compile-to-JS language with a number of interesting features, such as:
7+- Higher Kinded Polymorphism
8+- Support for basic Javascript types
11+- Type-safe blocks with for/while/assignment etc.
12+- Functions with multiple arguments
18+- Optional tail-call elimination
23+Try PureScript in the browser [here](http://tryps.functorial.com/).
27+Install the Haskell Plaform, then `cabal install`
31+The `psc` executable takes a list of PureScript source files as arguments and by default writes out its errors or output to the console.
33+The following options are supported:
36+ Read input from standard input instead of from files
39+ Write the generated Javascript to the specified file
42+ Write a list of foreign imports declarations to the specified file in addition to generating Javascript output
44+ --runtime-type-checks
45+ Generate simple runtime type checks for function arguments with simple types.
48+ Perform tail-call elimination on the generated Javascript.
51+ Do not include the Prelude in the generated Javascript.
54+ Overload the `do` keyword to inline calls to `bind` for the `Eff` monad, to generate more efficient code.
57+ Generate a call to `Main.main` after all other generated Javascript.
61+I was looking for a simple functional language which would compile to JavaScript and have the following characteristics:
63+- Generate simple readable Javascript
64+- Provide the ability to compile to tight loops if necessary
65+- Reasonable type system
66+- Ideally, written in a programming language I would enjoy working in
67+- Provides a simple interface to existing Javascript code
69+I didn't find exactly what I was looking for, so I wrote PureScript. It doesn't have everything right now, but it should serve as a simple core on which to develop new ideas.
71+PureScript is *not* designed to be a general-purpose programming language. The primary use case is as a generator for purely-functional core libraries, with the main application code written in another language.
73+PureScript can also be seen as a trade-off between a theoretically ideal language and one which generates reasonably high performance code.
77+As an introductory example, here is the usual "Hello World" written in PureScript:
84+main = trace "Hello, World!"
87+which compiles to the following Javascript, ignoring the Prelude:
92+ var main = trace("Hello, World!");
94+})(Main = Main || {});
97+The following command will compile and execute the PureScript code above:
100+psc input.purs --run-main | nodejs
105+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 }
110+foreign import numberToString :: Number -> String
112+showPerson :: Person -> String
113+showPerson (Person o) = o.name ++ ", aged " ++ numberToString(o.age)
116+Line by line, this reads as follows:
118+- `Person` is a data type with one constructor, also called `Person`
119+ - The `Person` constructor takes an object with two properties, `name` which is a `String`, and `age` which is a `Number`
120+- The `numberToString` function is written in Javascript, and converts a `Number` to its `String` representation
121+- 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.
124+The generated Javascript looks like this:
127+var Person = function (value) {
128+ return { ctor: 'Person', value: value };
131+function showPerson(_1) {
132+ if (_1.ctor === "Person") {
133+ return _1.value.name + ", aged " + numberToString(_1.value.age);
135+ throw "Failed pattern match";