This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* String must use double quotes */ | |
let myString = "Hello World!"; | |
let myInt = 5; | |
/* Float doesn't have to have a trailing 0 */ | |
let myFloat = 5.; | |
/* Char must use single quotes */ | |
let myChar = 'c'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type Animal = { | |
/* ... */ | |
let mate: (t('a), t('a)) => string; | |
let interMate: (t(dog), t(cat)) => string; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Link to playground: https://bit.ly/2J7t1bR */ | |
let larry = Animal.makeDog("Larry"); | |
let larsa = Animal.makeDog("Larsa"); | |
let mark = Animal.makeCat("Mark"); | |
let marla = Animal.makeCat("Marla"); | |
/* ✅ Mates 2 dogs and then mates 2 cats*/ | |
Js.log(Animal.mate(larry, larsa)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Animal: Animal = { | |
... | |
let mate = (x, y) => {j|🌈 $x and $y mated! 🌈|j}; | |
let interMate = (x, y) => {j|💩$x & $y are mating! WAT IS HAPPENING!💩|j}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type Animal = { | |
/* ... */ | |
let mate: (t('a), t('a)) => string; | |
let interMate: (t('a), t('b)) => string; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Link to playground: https://bit.ly/2IUSbXw */ | |
let larry = Animal.makeDog("Larry"); | |
let larsa = Animal.makeDog("Larsa"); | |
let mark = Animal.makeCat("Mark"); | |
let marla = Animal.makeCat("Marla"); | |
/* ✅ Mates 2 dogs and then mates 2 cats*/ | |
Js.log(Animal.mate(larry, larsa)); | |
Js.log(Animal.mate(mark, marla)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Animal: Animal = { | |
type t('a) = string; | |
type dog; | |
type cat; | |
let makeDog = d => d; | |
let makeCat = c => c; | |
let mate = (x, y) => {j|🌈 $x and $y mated! 🌈|j}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type Animal = { | |
/* Define abstract types t, dog, and cat */ | |
type t('a); | |
type dog; | |
type cat; | |
/* helpers to create a type dog or cat */ | |
let makeDog: string => t(dog); | |
let makeCat: string => t(cat); | |
let mate: (t('a), t('a)) => string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type t('a) = string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec min = node => | |
switch (node) { | |
| Empty => Empty | |
| Node({value, left, right}) => | |
if (left == Empty) { | |
node; | |
} else { | |
min(left); | |
} | |
}; |