Last active
July 6, 2016 22:07
-
-
Save homam/b5f7b2d5e37009a84e9071385671848b to your computer and use it in GitHub Desktop.
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
class Kleisli { | |
// given f :: x -> Monad y, constructs a category of type: | |
// Cat (x ↣ y) | |
constructor(f) { | |
// this.run = f | |
this.run = x => f(x) | |
// this :: Cat (x ↣ y) | |
// Cat (y ↣ z) -> Cat (x ↣ z) | |
this.pipe = g => new Kleisli(x => this.run(x).then(g.run)) // then == bind | |
// utility functon: | |
// this :: Cat (x ↣ y) | |
// (y -> Monad z) -> Cat (x ↣ z) | |
this.pipeTo = g => new Kleisli(x => this.run(x).then(g)) // then == bind | |
} | |
} | |
// Monad => Cat (x ↣ x) | |
Kleisli.id = monad => new Kleisli(x => monad.resolve(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment