-
Notifications
You must be signed in to change notification settings - Fork 7
Port "Language" section from reasonml.github.io #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
396e294 to
004d640
Compare
feihong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't converted the one-liner snippets past this point yet
|
|
||
| Feature | Example | ||
| --------------------------------|---------- | ||
| String | `"Hello"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.