Port "Language" section from reasonml.github.io#195
Conversation
396e294 to
004d640
Compare
feihong
left a comment
There was a problem hiding this comment.
@jchavarri I haven't yet finished adding the overview page of the Language section, but wanted to get your feedback before going any further
| { | ||
| text: "Language Basics", | ||
| items: [ | ||
| { text: "Overview", link: "/overview" }, |
There was a problem hiding this comment.
I've only added overview page so far
| Tuple | <code class="text-ocaml">let x: (int, string) = (10, "ten")</code><code class="text-reasonml">let x: (int, string) = (10, "ten");</code> | ||
| List | <code class="text-ocaml">let x: int list = [1; 2; 3];</code><code class="text-reasonml">let x: list(int) = [1, 2, 3];</code> | ||
| Array | <code class="text-ocaml">let x: int array = [|1; 2; 3|]</code><code class="text-reasonml">let x: array(int) = [|1, 2, 3|];</code> | ||
| Functions | <code class="text-ocaml">let x : int -> int -> int = fun a b -> a + b</code><code class="text-reasonml">let x: (int, int) => int = (a, b) => a + b;</code> |
There was a problem hiding this comment.
let x : int -> int -> int = fun a b -> a + bis not the most idiomatic way to define a function in OCaml syntax. But
let x a b = a + bDoesn't include the type annotation. Or maybe it could be this?
let x (a : int) (b : int) : int = a + b| Feature | Example | ||
| --------------------------------|---------- | ||
| If-Else expressions | <code class="text-ocaml">if condition then a else b</code><code class="text-reasonml">if (condition) { a; } else { b; }</code> | ||
| Ternary expressions | <span class="text-ocaml">not applicable</span><code class="text-reasonml">condition ? a : b;</code> |
There was a problem hiding this comment.
I use a span for the ocaml part since OCaml syntax has no ternary operator
| - Note: These are expressions and can be assigned to a variable: | ||
| <code class="text-ocaml">let x = if condition then a else b</code><code class="text-reasonml">let x = if (condition) { a; } else { b; };</code> | ||
|
|
||
| ## Functions |
There was a problem hiding this comment.
I haven't converted the one-liner snippets past this point yet
|
|
||
| Feature | Example | ||
| --------------------------------|---------- | ||
| String | `"Hello"` |
There was a problem hiding this comment.
For the cases where they're the same, I guess I can just leave them as-is? Do we want to have syntax highlighting for these short snippets? (Not sure if it's even possible.)
| IntPrinter.print(10); // 10 | ||
| IntPrinter.printList([1, 2, 3]); // 1, 2, 3 |
There was a problem hiding this comment.
Maybe this part should be changed to
let () = {
IntPrinter.print(10); // 10
IntPrinter.printList([1, 2, 3]); // 1, 2, 3
};to better match the OCaml syntax version?
Addresses #173
Need to also add a Syntax page that Language sidebar that explains the two different syntaxes and how to install Reason (#38). Probably add it as the first page under Language Basics sidebar section.