Question: Assume MLreadint and MLwriteint are primitives with side effects for input-output and consider the ML expression add1 of type int: let val x = MLreadint()
Assume MLreadint and MLwriteint are primitives with side effects for input-output and consider the ML expression add1 of type int: let val x = MLreadint() in MLwriteint(x+1); x end (i) Give an equivalent expression that uses the IO monad instead of side-effects and state its type. (ii) Give a function run2diff that can be applied to your answer to part (c)(i). When so applied it should give a value in the IO monad which corresponds to ML code that runs add1 twice and returns the difference between the values read.
Step by Step Solution
3.58 Rating (151 Votes )
There are 3 Steps involved in it
The detailed answer for the abov... View full answer
Get step-by-step solutions from verified subject matter experts
