forked from purescript/purescript.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
153 lines (129 loc) · 6.16 KB
/
index.html
File metadata and controls
153 lines (129 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>PureScript</title>
<link rel="stylesheet" href="./css/style.css" />
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:400,300,700" />
<link rel="icon" type="image/png" href="./img/favicon_clear-16.png" sizes="16x16">
<link rel="icon" type="image/png" href="./img/favicon_clear-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="./img/favicon_clear-256.png" sizes="256x256">
</head>
<body class="home">
<script>document.body.className = "home hasJS";</script>
<header>
<div class="wrap">
<h1><a href="../">PureScript</a></h1>
<nav>
<h2>Menu</h2>
<ul>
<li><a href="./" class="active">Home</a></li>
<li><a href="./download/">Download</a></li>
<li><a href="./learn/">Learn</a></li>
<li><a href="./community/">Community</a></li>
<li><a href="./projects/">Projects</a></li>
</ul>
</nav>
</div>
</header>
<main>
<section class="intro">
<h2>PureScript is a small strongly typed programming language that compiles to JavaScript.</h2>
<div class="link">
<a href="http://try.purescript.org/">Try It!</a>
</div>
</section>
<section class="example">
<h3>Examples</h3>
<div class="current example">
<h4>Modifying the DOM</h4>
<p>PureScript’s expressive type system and lightweight syntax make it simple to define <a href="https://leanpub.com/purescript/read#leanpub-auto-domain-specific-languages">domain-specific languages</a>, which can be used to solve problems like templating the DOM. Bindings also exist for libraries such as React and Virtual DOM.</p>
<p>
You can <a href="http://try.purescript.org/?gist=297b324cca7fdd6a802a7365c2c5ea62&backend=flare">try this example</a> online.
</p>
<pre>
<span class="kr">import</span> <span class="nn">Flare</span>
<span class="kr">import</span> <span class="nn">Flare.Smolder</span>
<span class="nf">ui</span> = greet <span class="kt"><$></span> string <span class="s">"Name"</span> <span class="s">"World"</span>
where
<span class="nf">greet</span> name = h1 <span class="kt">$</span> text <span class="kt">$</span> <span class="s">"Hello, "</span> <span class="kt"><></span> name <span class="kt"><></span> <span class="s">"!"</span></pre>
</div>
<div class="example">
<h4>HTML5 Canvas</h4>
<p>Higher-order functions allow the developer to write fluent, expressive code. Here, the higher-order function <code>thrice</code> is being used to simplify some code while <a href="https://leanpub.com/purescript/read#leanpub-auto-canvas-graphics">working with the canvas</a>.</p>
<p>
You can <a href="http://try.purescript.org/?gist=1c497b0533c1e1e4c21ebdbbd4195a79&backend=flare">try this example</a> online.
</p>
<pre>
<span class="kr">import</span> <span class="nn">Flare</span>
<span class="kr">import</span> <span class="nn">Flare.Drawing</span>
<span class="nf">thrice</span> f x = f (f (f x))
<span class="nf">scene</span> = thrice subdivide
$ outlined (outlineColor black)
$ circle <span class="mi">0.0</span> <span class="mi">0.0</span> <span class="mi">1.0</span></pre>
</div>
<div class="example">
<h4>Callback Hell</h4>
<p>The problem of <a href="https://leanpub.com/purescript/read#leanpub-auto-callback-hell">callback hell</a> can be solved by using PureScript’s type system to capture complex control flow as functions in a safe way. Here, the continuation monad is used to hide the boilerplate code associated with handling callbacks.</p>
<pre>
<span class="kr">import</span> <span class="nn">Control.Monad.Aff</span>
<span class="kr">data</span> <span class="kt">Model</span> = <span class="kt">Model</span> (<span class="kt">List Product</span>)
<span class="nf">loadModel</span> = <span class="kr">do</span>
popular <- get <span class="s">"/products/popular"</span>
products <- parTraverse (\product -> get product.uri) popular
pure (<span class="kt">Model</span> products)</pre>
</div>
<div class="example">
<h4>Generative Testing</h4>
<p>PureScript provides a form of ad-hoc polymorphism in the form of type classes, inspired by Haskell. Type classes are used in the QuickCheck and StrongCheck libraries to support <a href="https://leanpub.com/purescript/read#leanpub-auto-generative-testing">generative testing</a>, which separates test definitions from the generation of test cases.</p>
<p>
You can <a href="http://try.purescript.org/?gist=b291f5ce33b92885b8be069e6a6bddb8&backend=core">try this example</a> online.
</p>
<pre>
<span class="kr">import</span> <span class="nn">Test.QuickCheck</span>
<span class="nf">main</span> = <span class="kr">do</span>
quickCheck $ <span class="nf">\</span>xs ys ->
isSorted $ merge (sort xs) (sort ys)
quickCheck $ <span class="nf">\</span>xs ys ->
xs `isSubarrayOf` merge xs ys</pre>
</div>
</section>
<section class="features">
<h3>Features</h3>
<ul>
<li>Algebraic data types</li>
<li>Pattern matching</li>
<li>Type inference</li>
<li>Type classes</li>
<li>Higher kinded types</li>
<li>Rank-N types</li>
<li>Extensible records</li>
<li>Extensible effects</li>
<li>Modules</li>
<li>Simple FFI</li>
<li>No runtime system</li>
<li>Human-readable output</li>
</ul>
</section>
</main>
<footer>
<nav>
<ul>
<li><a href="./" class="active">Home</a></li>
<li><a href="./download/">Download</a></li>
<li><a href="./learn/">Learn</a></li>
<li><a href="./community/">Community</a></li>
<li><a href="./projects/">Projects</a></li>
</ul>
<ul class="external">
<li class="github"><a href="https://github.com/purescript/purescript" title="GitHub">GitHub</a></li>
<li class="twitter"><a href="https://twitter.com/purescript" title="Twitter">Twitter</a></li>
</ul>
</nav>
</footer>
<script src="js/lib/zepto-1.1.4.min.js"></script>
<script src="js/home.js"></script>
</body>
</html>