Skip to content

Instantly share code, notes, and snippets.

@WimJongeneel
Last active October 26, 2020 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WimJongeneel/f2951c238604c860f63fae639f8a074a to your computer and use it in GitHub Desktop.
Save WimJongeneel/f2951c238604c860f63fae639f8a074a to your computer and use it in GitHub Desktop.
/**
* Construct a continuation a' from a (f: (a:a') => void) => void
* @param c - the cont a'
*/
export const unit = <a>(f: (c: (_: a) => void) => void): Cont<a> => ({
run: c,
map<b>(f: (a: a) => b) {
return create_cont(cont_map(this.runCont, f))
},
then<b>(f: (a: a) => Cont<b>) {
return create_cont<b>(cont_bind<a, b>(this.runCont, a => f(a).run))
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment