Skip to content

Instantly share code, notes, and snippets.

Kennet Postigo kennetpostigo

View GitHub Profile
@kennetpostigo
kennetpostigo / NotAbstract.re
Created Jul 19, 2018
NotAbstract example from Universal and Existential Types in ReasonML blogpost
View NotAbstract.re
/* link to playground: https://bit.ly/2uCBISK */
module type Animal = {
type t = string;
let make: (string) => t;
let sprint: (t) => string;
};
module Animal: Animal = {
type t = string;
let make = (name) => name;
@kennetpostigo
kennetpostigo / ExistentialExample.re
Last active Jul 19, 2018
ExistentialTypesExample from Universal and Existential Types blog post
View ExistentialExample.re
/* link to playground: https://bit.ly/2uP4SgO */
module type Animal = {
type t;
let make: (string) => t;
let sprint: (t) => string;
};
module Animal: Animal = {
type t = string;
let make = (name) => name;
@kennetpostigo
kennetpostigo / ReasonBSTFull.re
Created Jun 25, 2018
Reason BST Blog Post full implementation
View ReasonBSTFull.re
type binarySearchTree('a) =
| Empty
| Node(node('a))
and node('a) = {
value: 'a,
left: binarySearchTree('a),
right: binarySearchTree('a),
};
let compare = (f, s) =>
@kennetpostigo
kennetpostigo / ReasonBSTPM.re
Created Jun 24, 2018
Reason BST Blog Post pattern matching
View ReasonBSTPM.re
type pets =
| Dog(string)
| Cat(string)
| Hamster(string);
let myPet = Dog("Buddy");
switch (myPet) {
| Dog(name) => "I have a Dog " ++ name ++ "!"
| Cat(name) => "I have a Cat " ++ name ++ "!"
@kennetpostigo
kennetpostigo / ReasonBSTPMS.re
Created Jun 24, 2018
Reason BST Blog Post pattern matching syntax
View ReasonBSTPMS.re
/* Typical pattern matching with a switch */
switch (expression) {
| pattern1 => expression1
| pattern2 => expression2
| ...
| patternN => expressionN
};
/* Typical destructuring for tuple*/
let (x, y) = tupleOfXY;
@kennetpostigo
kennetpostigo / ReasonBSTVariant.re
Last active Jun 26, 2018
Reason BST Blog Post variants
View ReasonBSTVariant.re
/* pet is called a type constructor. Dog, Cat, and
Hamster are called value constructors or tags*/
type pet =
| Dog
| Cat
| Hamster;
/* myPet is of type pet */
let myPet = Dog;
@kennetpostigo
kennetpostigo / ReasonBSTRecords.re
Created Jun 24, 2018
Reason BST Blog Post records
View ReasonBSTRecords.re
type dog = {
name: string,
breed: string,
age: int
};
let myFirstDog = {
name: "Bubbly",
breed: "Poodle",
age: 3
@kennetpostigo
kennetpostigo / ReasonBSTTuples.re
Created Jun 24, 2018
Reason BST Blog Post tuples
View ReasonBSTTuples.re
let intStringFloat = (1, "one", 1.0);
let tripleStrings = ("Kennet", "Postigo", "@kennetpostigo");
@kennetpostigo
kennetpostigo / ReasonBSTTypes.re
Last active Jun 25, 2018
Reason BST Blog Post types
View ReasonBSTTypes.re
/* waddup annotated as a string */
let waddup: string = "waddup fam?!?!";
/* greeting annotated as a function that takes a string and returns string */
let greeting: string => string = name => "Hey " ++ name ++ "!";
/* Type constructor for a function that takes a string and returns unit */
type nonPureGreeting = string => unit;
/* printGreet annotated as nonPureGreeting*/
@kennetpostigo
kennetpostigo / ReasonBSTFunctions.re
Created Jun 24, 2018
Reason BST Blog Post functions
View ReasonBSTFunctions.re
let greet = name => "Hey " ++ name ++ "!"; /* returns string */
let double = x => x * x;
/* Returns unit, signifying it isn't pure and has side-effects */
let printGreet = name => {
let greeting = greet(name);
print_string(greeting);
};
You can’t perform that action at this time.