Skip to content
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

Port "Language" section from reasonml.github.io #195

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

feihong
Copy link
Collaborator

@feihong feihong commented Oct 10, 2024

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.

Copy link
Collaborator Author

@feihong feihong left a 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" },
Copy link
Collaborator Author

@feihong feihong Oct 10, 2024

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 = [&#124;1; 2; 3&#124;]</code><code class="text-reasonml">let x: array(int) = [&#124;1, 2, 3&#124;];</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>
Copy link
Collaborator Author

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 + b

is not the most idiomatic way to define a function in OCaml syntax. But

let x a b = a + b

Doesn'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>
Copy link
Collaborator Author

@feihong feihong Oct 10, 2024

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
Copy link
Collaborator Author

@feihong feihong Oct 10, 2024

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"`
Copy link
Collaborator Author

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.)

Comment on lines +376 to +377
IntPrinter.print(10); // 10
IntPrinter.printList([1, 2, 3]); // 1, 2, 3
Copy link
Collaborator Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant