forked from PrismJS/prism
/
prism-rescript.html
51 lines (43 loc) · 1.14 KB
/
prism-rescript.html
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
<h2>Comments</h2>
<pre><code>/* This is a comment */
// Another comment
</code></pre>
<h2>Let bindings</h2>
<pre><code>let name = "Alonzo Church"
let message = `Hello ${name}`
let message2 = `Hello ${person.name}`
let result = `Testing => ${Module.Another.value}`
let value = 1
let result = 1 + 1
let langs = ["ReScript", "JavaScript"]
let person = ("Alonzo", 32)</code></pre>
<h2>Type declarations & Functions</h2>
<pre><code>type role = | Admin | Editor | Viewer
type numeric = #1 | #2 | #3
type normal = #Poly | #Variant
type myPolyVar = [ #"poly-variant" | #"test-chars" ]
type person = {
name: string,
age: int,
role: role
}
type record = {
"field": string
}
let sum = (a, b) => a + b
let sum2 = (a:int, b: int) => a + b</code></pre>
<h2>Modules, JSX & Components</h2>
<pre><code>module Button = {
@react.component
let make = (~count: int) => {
let times = switch count {
| 1 => "once"
| 2 => "twice"
| n => Belt.Int.toString(n) ++ " times"
}
let msg = "Click me " ++ times
<button onClick={Js.log}>{msg->React.string}</button>;
}
}
@react.component
let make = () => <MyModule.Button count=1 /></code></pre>