Created
January 6, 2019 17:20
-
-
Save eyelash/712f87d671697c7b51443819347821b2 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
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