Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of a monad written in ReasonML.
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