rauschma / exploring-reasonml

http://reasonmlhub.com/exploring-reasonml/
26 stars 0 forks source link

Chapter: A first look at ReasonML’s syntax #5

Open rauschma opened 6 years ago

rauschma commented 6 years ago

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

nhducit commented 6 years ago
type tree('a) =
  | Empty
  | Node('a, tree('a), tree('a));

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

rauschma commented 6 years ago

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.

approots commented 6 years ago

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.

nhducit commented 6 years ago

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

dp-1a commented 6 years ago

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");
rauschma commented 6 years ago

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

craigglennie commented 6 years ago

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"?

rauschma commented 6 years ago

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

rauschma commented 6 years ago

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

bhongy commented 6 years ago

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) =>
idkjs commented 6 years ago

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 = /

rauschma commented 6 years ago

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

mars0i commented 6 years ago

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!

osenvosem commented 6 years ago

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.

rauschma commented 6 years ago

@osenvosem Good catch! Fixed now, thanks.