Open rauschma opened 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?
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.
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.
I mean at least we should mention it, and point to the explanation in further chapter
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 “myBook” is the typo. It’ll be fixed in the next release. Thanks!
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"?
@approots @nhducit Thanks for your feedback! I’ve updated the chapter: http://reasonmlhub.com/exploring-reasonml/ch_syntax-overview.html
@craigglennie True! It’ll be fixed in the next release. Thanks!
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) =>
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 = /
@bhongy & @idkjs: Those were typos and are fixed now. Thanks for the feedback!
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!
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 Good catch! Fixed now, thanks.
http://reasonmlhub.com/exploring-reasonml/ch_syntax-overview.html