Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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