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 orig开发者_如何学Pythoninal ref now, considering x := 50 is going to apply to the SECOND x now....
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
There is no way to access original x
now. So.. shadow f
!
精彩评论