Skip to content

Instantly share code, notes, and snippets.

View kennetpostigo's full-sized avatar
🏠
Working from home

Kennet Postigo kennetpostigo

🏠
Working from home
View GitHub Profile
@kennetpostigo
kennetpostigo / ReasonBSTPrimitives.re
Created June 24, 2018 14:23
Reason BST Blog Post primitives
/* 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';
@kennetpostigo
kennetpostigo / ReasonAnimalTypeInter.re
Created June 23, 2018 00:53
Reason Phantom Type Animal Strict dog and cat
module type Animal = {
/* ... */
let mate: (t('a), t('a)) => string;
let interMate: (t(dog), t(cat)) => string;
};
@kennetpostigo
kennetpostigo / ReasonAnimalUsageCatchAll.re
Created June 23, 2018 00:51
Reason Phantom Type Animal catch all usage
/* 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));
@kennetpostigo
kennetpostigo / ReasonAnimalCatchAll.re
Created June 23, 2018 00:49
Reason Phantom Type Animal catch all
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};
};
@kennetpostigo
kennetpostigo / ReasonAnimalTypeCatchAll.re
Last active June 23, 2018 00:49
Reason Phantom Type Animal Type catch all
module type Animal = {
/* ... */
let mate: (t('a), t('a)) => string;
let interMate: (t('a), t('b)) => string;
};
@kennetpostigo
kennetpostigo / ReasonAnimalUsage.re
Last active June 23, 2018 00:51
Reason Phantom Type Animal usage
/* 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));
@kennetpostigo
kennetpostigo / ReasonAnimal.re
Created June 23, 2018 00:43
Reason Phantom Type Animal module
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};
};
@kennetpostigo
kennetpostigo / ReasonAnimalType.re
Last active June 23, 2018 00:42
Reason Phantom Type Animal module type
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;
@kennetpostigo
kennetpostigo / ReasonGenericPhantomType.re
Last active June 23, 2018 00:40
Reason Phantom Types Blog Post generic phantom type
type t('a) = string;
@kennetpostigo
kennetpostigo / ReasonBSTMin.re
Created June 22, 2018 23:24
Reason Blog Post min
let rec min = node =>
switch (node) {
| Empty => Empty
| Node({value, left, right}) =>
if (left == Empty) {
node;
} else {
min(left);
}
};