Question

let x = ref 100 in
let f () = !x in
let x = ref 50 in
??? ; f ()

You are supposed to get the answer to be 50 by plugging something into the ??? (not shadowing). But I don't know how to change the value of your original ref now, considering x := 50 is going to apply to the SECOND x now....

Was it helpful?

Solution

If it really is a "beginner question", that's probably not the expected answer. But I don't know what the "expected answer" is, so let's hack around instead.

Obj.(obj (field (repr f) 1)) := 42;;

relevant link

OTHER TIPS

There is no way to access original x now. So.. shadow f!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top