Created
October 23, 2017 18:53
-
-
Save haskellcamargo/bdb0daf36958a49de2b56d6275db20d7 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
const _effect = evaluator => ({ type: 'effect', evaluator }); | |
const _mut = evaluator => ({ type: 'mut', evaluator }); | |
const _while = (condition, body) => env => { | |
if (condition(env)) { | |
const state = body.reduce((env, elem) => { | |
if (elem.type === 'effect') { | |
void elem.evaluator(env); | |
return env; | |
} else if (elem.type === 'mut') { | |
return elem.evaluator(env); | |
} | |
}, env); | |
_while(condition, body)(state); | |
} | |
}; | |
_while( | |
({ i }) => i < 10, | |
[ | |
_effect(({ i }) => console.log(i)), | |
_mut(({ i }) => ({ i: i + 1 })) | |
] | |
)({ i: 0 }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment