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

1 Expert Approved Answer
Step: 1 Unlock

The detailed answer for the abov... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!