Last active
January 29, 2020 22:22
-
-
Save mlms13/3b22abda2981b5f5e9360caea43f947d to your computer and use it in GitHub Desktop.
Reader, I guess
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
let const = (a, _) => a; | |
let (<<) = (f, g, a) => f(g(a)); | |
module type Type = {type t;}; | |
module Function1 = { | |
type t('input, 'output) = 'input => 'output; | |
}; | |
module type Functor = { | |
type t('a); | |
let map: ('a => 'b, t('a)) => t('b); | |
}; | |
module type Apply = { | |
include Functor; | |
let liftA2: (('a, 'b) => 'c, t('a), t('b)) => t('c); | |
}; | |
module type Applicative = { | |
include Apply; | |
let pure: 'a => t('a); | |
}; | |
module type Monad = { | |
include Applicative; | |
let flatMap: ('a => t('b), t('a)) => t('b); | |
}; | |
module Reader = (Input: Type) : Monad => { | |
type t('a) = Function1.t(Input.t, 'a); | |
let map = (<<); | |
let liftA2 = (f, a, b, input) => f(a(input), b(input)); | |
let pure = const; | |
let flatMap = (f, a, input) => f(a(input), input); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment