Skip to content

Instantly share code, notes, and snippets.

@dangdennis
Created December 1, 2018 03:47
Show Gist options
  • Save dangdennis/f52ec17e0296ff51617da9b06315d38e to your computer and use it in GitHub Desktop.
Save dangdennis/f52ec17e0296ff51617da9b06315d38e to your computer and use it in GitHub Desktop.
/* This is a variant of type animal */
type animal =
| Cat
| Dog;
/* This is a record of type cat */
type cat = {
name: string,
species: animal /* animal can be Cat or Dog */
/* color: string */
};
let someCat = {name: "Fooz", species: Cat};
let someDog = {name: "Buzz", species: Dog};
/* let someHorse = {
name: "Neeiighbor",
species: Horse
};
*/
let listOfAnimals = [
{name: "Persian", species: Cat},
{name: "Siamese", species: Cat},
{name: "Scottish Fold", species: Cat},
{name: "Bombay", species: Cat},
{name: "Corgi", species: Dog},
];
let catsOnly = List.filter(animal => animal.species === Cat, listOfAnimals);
let catNamesOnly = List.map(animal => animal.name, catsOnly);
/* let catNamesOnly: list(string) = ["Persian", "Siamese", "Scottish Fold", "Bombay"]; */
let dogsOnly = List.filter(animal => animal.species === Dog, listOfAnimals);
/* let dogsOnly: list(cat) = [{name: "Corgi", species: Dog}]; */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment