Teaching ReasonML

SWBAT: Write a todo list in ReasonML?

Why Reason?

Basic Setup:

Install build system

# provides the BuckleScript compiler
npm install -g bs-platform

# Provides integration with VScode or whatever
npm install -g reason-cli@3.1.0-darwin

Make a basic reason app:

# creates project my-first-app/ 
# ompiles to src/Demo.bs.js using BuckleScript compiler
# and runs the demo using NodeJS
bsb -init my-first-app -theme basic-reason  
cd my-first-app
npm run build
node src/Demo.bs.js

Make a ReasonReact app:

bsb -init my-react-app -theme react.

Basic types

/* immutable variable assigned to an int */
let a = 1;

/* immutable variable assigned to an float */
let b = 1.0;

Lists

Lists are linked lists they don't have random-access (you can't get the middle of them efficiently) but they are cheaper to add items to. Makes less of a difference in JS.

let c = [1, 2, 3];

They don't allow different types in the same thing.

Tuples

tuples are like elixir tuples. They use ()'s though

kind of like fixed length, polymorphic arrays. Or a struct were you're too lazy to name the fields.

Arrays

arrays have a different syntax and they allow random access

let d = [|1, 2, 3|];

This defines a struct. They have a fixed number of fields. They all must be present.

type person = {
	name: string,
	age: string
};


let gage = {name: "gage"}

Minting new types

GOTO 2018 • Unconditional Code • Michael Feathers - YouTube

Don't be "stringly" typed...

Ode to the overloaded string...

often used for

var BLUE = "blue";
var RED = "red";
var colors = [BLUE, RED] 

reason teaching


Backlinks: