| 1 | <h2>Comments</h2> |
| 2 | <pre><code>/* This is a comment */ |
| 3 | // Another comment |
| 4 | </code></pre> |
| 5 | |
| 6 | <h2>Let bindings</h2> |
| 7 | <pre><code>let name = "Alonzo Church" |
| 8 | let message = `Hello ${name}` |
| 9 | let message2 = `Hello ${person.name}` |
| 10 | let result = `Testing => ${Module.Another.value}` |
| 11 | let value = 1 |
| 12 | let result = 1 + 1 |
| 13 | let langs = ["ReScript", "JavaScript"] |
| 14 | let person = ("Alonzo", 32)</code></pre> |
| 15 | |
| 16 | <h2>Type declarations & Functions</h2> |
| 17 | <pre><code>type role = | Admin | Editor | Viewer |
| 18 | type numeric = #1 | #2 | #3 |
| 19 | type normal = #Poly | #Variant |
| 20 | type myPolyVar = [ #"poly-variant" | #"test-chars" ] |
| 21 | |
| 22 | type person = { |
| 23 | name: string, |
| 24 | age: int, |
| 25 | role: role |
| 26 | } |
| 27 | |
| 28 | type record = { |
| 29 | "field": string |
| 30 | } |
| 31 | |
| 32 | let sum = (a, b) => a + b |
| 33 | let sum2 = (a:int, b: int) => a + b</code></pre> |
| 34 | |
| 35 | <h2>Modules, JSX & Components</h2> |
| 36 | <pre><code>%%raw(``) |
| 37 | module Button = { |
| 38 | @react.component |
| 39 | let make = (~count: int) =>{ |
| 40 | let times = switch count { |
| 41 | | 1 => "once" |
| 42 | | 2 => "twice" |
| 43 | | n => Belt.Int.toString(n) ++ " times" |
| 44 | } |
| 45 | let msg = "Click me " ++ times |
| 46 | |
| 47 | <button onClick={Js.log}>{msg->React.string}</button>; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | @react.component |
| 52 | let make = () => <MyModule.Button count=1 /></code></pre> |