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
83 lines (76 loc) · 4.4 KB
/
index.html
File metadata and controls
83 lines (76 loc) · 4.4 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
<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 Angular.js.</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> :: UI _ H.Markup
<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, higher-order functions are being used to capture some common patterns when <a href="https://leanpub.com/purescript/read#leanpub-auto-canvas-graphics">working with HTML5 canvas</a>, such as closing and filling paths.</p>
<pre>
<span class="kr">import</span> <span class="nn">Control.Apply</span>
<span class="kr">import</span> <span class="nn">Graphics.Canvas.Free</span>
<span class="nf">scene</span> =
filled $ closed <span class="kr">do</span>
moveTo <span class="mi">0</span> <span class="mi">0</span>
lineTo <span class="mi">50</span> <span class="mi">0</span>
lineTo <span class="mi">25</span> <span class="mi">50</span>
<span class="kr">where</span>
<span class="nf">closed</span> path = beginPath *> path <* closePath
<span class="nf">filled</span> shape = shape <* fill</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">import</span> <span class="nn">Control.Monad.Aff.Par</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 <- runPar $ for_ popular \product -> <span class="kt">Par</span> (get product.uri)
return $ <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>
<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>