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 / NotAbstract.re
Created July 19, 2018 21:59
NotAbstract example from Universal and Existential Types in ReasonML blogpost
/* 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 July 19, 2018 21:56
ExistentialTypesExample from Universal and Existential Types blog post
/* 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 June 25, 2018 15:30
Reason BST Blog Post full implementation
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 June 24, 2018 14:34
Reason BST Blog Post pattern matching
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 June 24, 2018 14:33
Reason BST Blog Post pattern matching syntax
/* 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 June 26, 2018 15:32
Reason BST Blog Post variants
/* 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 June 24, 2018 14:30
Reason BST Blog Post records
type dog = {
name: string,
breed: string,
age: int
};
let myFirstDog = {
name: "Bubbly",
breed: "Poodle",
age: 3
@kennetpostigo
kennetpostigo / ReasonBSTTuples.re
Created June 24, 2018 14:29
Reason BST Blog Post tuples
let intStringFloat = (1, "one", 1.0);
let tripleStrings = ("Kennet", "Postigo", "@kennetpostigo");
@kennetpostigo
kennetpostigo / ReasonBSTTypes.re
Last active June 25, 2018 14:56
Reason BST Blog Post types
/* 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 June 24, 2018 14:24
Reason BST Blog Post functions
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);
};