关于 Ocaml Refs 的初学者问题

发布于 2024-11-07 01:49:37 字数 179 浏览 11 评论 0原文

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

通过将一些东西插入 ??? ,你应该得到 50 的答案。 (不是阴影)。但我现在不知道如何更改原始引用的值,考虑到 x := 50 现在将应用于第二个 x....

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....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

○愚か者の日 2024-11-14 01:49:37

如果这确实是一个“初学者问题”,那可能不是预期的答案。但我不知道“预期答案”是什么,所以让我们来解决一下。

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

相关链接

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

江南烟雨〆相思醉 2024-11-14 01:49:37

现在无法访问原始的x。所以..影子f

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文