Haskell 模块:隐藏名称和 ghci

发布于 2024-10-06 16:00:55 字数 446 浏览 0 评论 0原文

我试图从 Haskell 模块导出名称的子集,但 ghci 很高兴让我访问甚至隐藏的名称。

module Hiding (shown, calc) where

calc = shown * hidden

shown :: Int
shown = 3

hidden :: Int
hidden = 2

但是当在 ghci 中尝试这个时,我得到:

Prelude> :l Hiding.hs 
[1 of 1] Compiling Hiding           ( Hiding.hs, interpreted )
Ok, modules loaded: Hiding.
*Hiding> hidden
2

我做错了什么?

(编辑:就其价值而言,我在 Arch Linux 上使用 ghci 6.12.3)

I'm trying to export just a subset of names from a Haskell module, but ghci happily lets me access even the hidden names.

module Hiding (shown, calc) where

calc = shown * hidden

shown :: Int
shown = 3

hidden :: Int
hidden = 2

But when trying this in ghci I get:

Prelude> :l Hiding.hs 
[1 of 1] Compiling Hiding           ( Hiding.hs, interpreted )
Ok, modules loaded: Hiding.
*Hiding> hidden
2

What am I doing wrong?

(Edit: for what it's worth, I'm using ghci 6.12.3 on Arch Linux)

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

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

发布评论

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

评论(2

德意的啸 2024-10-13 16:00:55

看起来 GHCi 正在加载您的模块供您检查它,即将您置于模块的范围内。两个提示是提示符 *Hiding> 和您访问了隐藏功能的事实。

编辑:
到此为止: http://www. haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#id3045728

It looks like GHCi is loading your module for you to inspect it, i.e. putting you in the scope of the module. Two hints at that are the prompt *Hiding> and the fact that you accessed the hidden function.

Edit:
End there it is: http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#id3045728

萌吟 2024-10-13 16:00:55

在我看来你做了正确的事。如果您尝试从另一个模块引用该模块,我敢打赌 hidden 会拒绝工作。 GHCI 可能是无所不知的:)

It looks to me like you've done the right thing. If you attempt to reference that module from another module I'll bet hidden refuses to work. Could be that GHCI is all-knowing :)

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