This file contains hidden or 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/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; |
This file contains hidden or 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/2uP4SgO */ | |
module type Animal = { | |
type t; | |
let make: (string) => t; | |
let sprint: (t) => string; | |
}; | |
module Animal: Animal = { | |
type t = string; | |
let make = (name) => name; |
This file contains hidden or 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 binarySearchTree('a) = | |
| Empty | |
| Node(node('a)) | |
and node('a) = { | |
value: 'a, | |
left: binarySearchTree('a), | |
right: binarySearchTree('a), | |
}; | |
let compare = (f, s) => |
This file contains hidden or 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 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 ++ "!" |
This file contains hidden or 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
/* Typical pattern matching with a switch */ | |
switch (expression) { | |
| pattern1 => expression1 | |
| pattern2 => expression2 | |
| ... | |
| patternN => expressionN | |
}; | |
/* Typical destructuring for tuple*/ | |
let (x, y) = tupleOfXY; |
This file contains hidden or 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
/* 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; |
This file contains hidden or 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 dog = { | |
name: string, | |
breed: string, | |
age: int | |
}; | |
let myFirstDog = { | |
name: "Bubbly", | |
breed: "Poodle", | |
age: 3 |
This file contains hidden or 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 intStringFloat = (1, "one", 1.0); | |
let tripleStrings = ("Kennet", "Postigo", "@kennetpostigo"); |
This file contains hidden or 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
/* 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*/ |
This file contains hidden or 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 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); | |
}; |
NewerOlder