Created
December 5, 2018 10:00
-
-
Save KatagiriSo/b15f8bd0d01559dc9178c748a5f1e49c 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
// created by KatagiriSo Rodhos Soft | |
type EnvMonad<T,E> = (env:E) => T | |
const unit = <T,E>(t:T) => (env:E) => t; | |
const bind = <T1,T2,E>(e:EnvMonad<T1,E>, f:(t1:T1)=>EnvMonad<T2,E>) => { | |
return (env:E) => f(e(env))(env) | |
} | |
function envMonadTest() { | |
const f = (i:number) => (env:number) => i*env; | |
const m = unit<number, number>(10); | |
const mm = bind(m, f); | |
const ans = mm(5); // env 5 | |
console.log("ans == ", ans) // 10*5 = 50; | |
} | |
envMonadTest(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment