exploring-reasonml icon indicating copy to clipboard operation
exploring-reasonml copied to clipboard

Chapter: A first look at ReasonML’s syntax

Open rauschma opened this issue 7 years ago • 15 comments

http://reasonmlhub.com/exploring-reasonml/ch_syntax-overview.html

rauschma avatar Feb 07 '18 06:02 rauschma

type tree('a) =
  | Empty
  | Node('a, tree('a), tree('a));

I come from JS. what is 'a mean? Can you explain it?

nhducit avatar Feb 08 '18 03:02 nhducit

tree is a variant, 'a is a type variable (similar to a generic class Tree<A> in Java). Explained here: http://reasonmlhub.com/exploring-reasonml/ch_variants.html

The point of the example was to give a first taste of the syntax. No worries if you don’t understand it (yet)! I’ll clarify that in the text.

rauschma avatar Feb 08 '18 03:02 rauschma

For me, it's too early in the book to introduce that concept. I'm likely to write-off Reason as too complex for now.

approots avatar Feb 08 '18 21:02 approots

I mean at least we should mention it, and point to the explanation in further chapter

nhducit avatar Feb 09 '18 03:02 nhducit

Probably a typo in the code example in the chapter "Most things are expressions"?

let myBool = true; /* should be myBook? */
let print(if (myBook) "yes" else "no");

dp-1a avatar Feb 09 '18 09:02 dp-1a

@dp-1a “myBook” is the typo. It’ll be fixed in the next release. Thanks!

rauschma avatar Feb 09 '18 09:02 rauschma

ReasonML is based on OCaml, which uses snake-casing for lowercase names (create_resource) and camel-casing for uppercase names (StringUtilities).

That’s why you’ll occasionally see camel-cased names. But all new ReasonML code is camel-cased (StringUtilities, createResource).

I think "That’s why you’ll occasionally see camel-cased names" should be "That’s why you’ll occasionally see snake-cased names"?

craigglennie avatar Feb 09 '18 21:02 craigglennie

@approots @nhducit Thanks for your feedback! I’ve updated the chapter: http://reasonmlhub.com/exploring-reasonml/ch_syntax-overview.html

rauschma avatar Feb 11 '18 07:02 rauschma

@craigglennie True! It’ll be fixed in the next release. Thanks!

rauschma avatar Feb 11 '18 07:02 rauschma

I'm going through the book and found it's very easy to digest and concise. Thank you for writing it!

Possibly typo in one of the examples on this page (won't compile):

/* A function that switches over a variant type */
let stringOfColor(c: color) =>
  switch (c) {
  | Red => "Red"
  | Green => "Green"
  | Blue => "Blue"
  };

Should the line with let binding be?:

let stringOfColor = (c: color) =>

bhongy avatar Feb 12 '18 03:02 bhongy

Probably a typo in the code example in the chapter "Most things are expressions"?

let myBool = true; let print = if (myBool) {"yes"} else {"no"}; /* print = /*

idkjs avatar Mar 21 '18 12:03 idkjs

@bhongy & @idkjs: Those were typos and are fixed now. Thanks for the feedback!

rauschma avatar Apr 08 '18 06:04 rauschma

There are many Initial_uppercase_and_then_snake module names in OCaml.

I don't think of x' in math or OCaml as meaning "changed x". I think of it as nothing more than "another x".

Thanks for making the book available online!

mars0i avatar May 18 '18 11:05 mars0i

This syntax at the end of the chapter seems to be deprecated:

let len(arr: array('a)) = Array.length(arr);

refmt changes it to:

let len = (arr: array('a)) => Array.length(arr);

rtop accepts and executes it, though.

osenvosem avatar Jun 05 '18 16:06 osenvosem

@osenvosem Good catch! Fixed now, thanks.

rauschma avatar Jun 10 '18 11:06 rauschma