Created
December 1, 2018 03:48
-
-
Save dangdennis/bdd62649e08179f1327b48376d919e41 to your computer and use it in GitHub Desktop.
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
open Belt | |
/* 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 animalNamesOnly = List.map(listOfAnimals, animal => animal.name); | |
/* 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