Created
January 24, 2019 11:15
-
-
Save KinoAR/de04d7d0224b214cd14d4a2cde0b41cd to your computer and use it in GitHub Desktop.
An example of a monad written in ReasonML.
This file contains 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 collection('a) = Collection('a) | None; | |
module CollectionMonad = { | |
let lift = (value) => Collection(value); | |
let map = (fn, x) => { | |
switch (x) { | |
| Collection(value) => Collection(fn(value)) | |
| None => None | |
} | |
} | |
let flatMap = (fn, collection) => switch(collection) { | |
| Collection(value) => fn(value) | |
| None => None | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment