Skip to content

Instantly share code, notes, and snippets.

@eyelash
Created January 6, 2019 17:20
Show Gist options
  • Save eyelash/712f87d671697c7b51443819347821b2 to your computer and use it in GitHub Desktop.
Save eyelash/712f87d671697c7b51443819347821b2 to your computer and use it in GitHub Desktop.
typealias IO<T> = () -> T
fun getChar(): IO<Char> {
return {
'x'
}
}
fun putChar(c: Char): IO<Unit> {
return {
print(c)
}
}
fun <T, U> IO<T>.bind(f: (T) -> IO<U>): IO<U> {
return {
f(this())()
}
}
fun _main(): IO<Unit> {
return getChar().bind { c ->
putChar(c).bind {
putChar(c)
}
}
}
fun main() {
_main()()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment