@@ -0,0 +1,121 @@
1+[](http://purescript.org)
3+**Pure11** is an experimental C++11/native compiler backend for [PureScript](https://github.com/purescript/purescript). It attempts to generate "sane", performant, and portable C++11 code as an intermediate language, which is then compiled to a native executable binary. This enables easy interoperability with existing C/C++ frameworks and libraries on a number of platforms.
7+### **Please note that this project and [purescript-c++](https://github.com/pure11/purescript-c++) are now the same**
13+* No runtime system (beyond some support classes and the standard C++11 runtime library)
14+* For automatic memory management, uses either native C++11 reference counting (`std::shared_ptr`), or the [Boehm-Demers-Weiser Garbage Collector](http://hboehm.info/gc/) -- **selectable when building** (see instructions below)
15+* Uses PureScript's normal tail call optimizations for generated C++11 code
17+#### Differences from PureScript:
19+* Foreign imports are C++11 (or C) instead of JavaScript ([FFI examples](https://github.com/pure11/pure11/wiki/FFI_Examples))
20+* Foreign functions are not written as curried functions (any necessary currying is done implicitly by the compiler)
21+* Compiler is `pcc` instead of `psc`, `make` is recommended for building
22+* No Pure11-specific REPL
26+* PureScript arrays are implmented using [`std::deque`](http://en.cppreference.com/w/cpp/container/deque) (random access *O(1)*)
27+* `String` types are implmented using either C-strings (for literals) or `std::string`
28+* `Number` is C++ `double`, `Int` is C++ `int`, `Char` is `char`, `Boolean` is `bool`
29+* [The current tested/supported package set is here.](https://github.com/pure11/package-sets/blob/psc-0.10.2/packages.json) Please feel free to submit a PR if you've had success with any others.
33+* Get automated builds/tests fully up and running [(some work already done)](https://github.com/pure11/purescript/blob/pure11/pcc/TestMain.hs)
34+* Unicode (UTF-8) support for `String` (possibly use code from my Idris backend)
39+* Nice facilities (modules) for concurrency/parallelism, using `std::thread`, `std::async`, etc. under the hood
40+* `BigInt` via GNU GMP (or an alternative)
44+* Everything you need to build [PureScript](https://github.com/purescript/purescript)
45+* A C++11-capable toolchain, e.g. recent versions of clang, gcc, Microsoft Visual Studio 2015
46+* GNU Make is the default supported build tool, but you should be able to use your favorite C++ build system, tools, debuggers, etc.
54+ import Control.Monad.Eff.Console (log, logShow)
59+ fib n = fib (n - 2) + fib (n - 1)
62+ log "Here's the result of fib 10:"
67+#include "Main/Main.hh"
69+ using namespace PureScript;
70+ using namespace Prelude;
71+ using namespace Control_Monad_Eff_Console;
72+ using namespace Data_Semiring;
73+ using namespace Data_Ring;
74+ using namespace Control_Bind;
75+ using namespace Control_Monad_Eff;
76+ using namespace Data_Show;
78+ auto fib(int v) -> int {
79+ switch (cast<int>(v)) {
83+ return fib(v - 2) + fib(v - 1);
86+ Control_Monad_Eff_Console::log("Here's the result of fib 10:")();
87+ return Control_Monad_Eff_Console::logShow(Data_Show::showInt, fib(10))();
91+auto main(int, char *[]) -> int {
92+ using namespace Main;
99+#### [FFI examples](https://github.com/pure11/pure11/wiki/FFI_Examples)
102+This assumes you are running OS X or a Unix-like system (Linux, *BSD, etc.), and already have the ability to [build PureScript from source] (http://www.purescript.org/download/) (bottom of the page) -- but instead of cloning and building the repository in the instructions, make sure to use [this project's repo](https://github.com/pure11/purescript).
104+1. Make sure you have developer tools for your system installed. For OS X, you'll need a recent version of Xcode. For Linux, etc., you need gcc 4.9.2 or later, including g++ support. You can also use clang 3.5 or later, but it still requires gcc for its C++ standard libraries.
106+2. **Optional and advanced:** If you wish to use the Boehm garbage collector (better runtime performance, in general, but less tested), install it for your system. For OS X, [brew](http://brew.sh/) is an easy method and recommended (package `bdw-gc`). For linux, it's available under package names such as `libgc-dev` (for Debian/Ubuntu).
108+3. Create a working directory wherever you like, and a `src` subdirectory under it, which will be where you will place your own PureScript source files.
110+4. From your working directory, run the `{installation_path}/pcc` command with no arguments. This will generate `Makefile` and `psc-package.json` files in that directory. There are some usage notes in the generated `Makefile`.
112+5. Use PureScript's standard `psc-package` utility to add and manage package dependencies.
114+6. You should now be ready to build a PureScript program.
115+ * As stated above, place your source file(s) in the working directory's `src` subdirectory and execute `make`. If your machine has multiple cores, you might want to use `make -jN`, where `N` is the number of cores.
117+ * **Optional and advanced:** To use the garbage collector, add `GC=yes` to the `make` command line (or you can modify the `Makefile` that you generated in step 4).
119+ * This will generate the C++ source tree for your program and then build an executable binary. The resulting executable will be in the `bin` subdirectory under the output directory and called `main` (so `output/bin/main`, by default).