简体   繁体   English

Haskell模块:隐藏名称和ghci

[英]Haskell modules: hidden names and ghci

I'm trying to export just a subset of names from a Haskell module, but ghci happily lets me access even the hidden names. 我正在尝试从Haskell模块中导出一个名称的子集,但是ghci很高兴让我访问隐藏的名称。

module Hiding (shown, calc) where

calc = shown * hidden

shown :: Int
shown = 3

hidden :: Int
hidden = 2

But when trying this in ghci I get: 但是当我在ghci中尝试这个时,我得到:

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) (编辑:为了它的价值,我在Arch Linux上使用ghci 6.12.3)

It looks like GHCi is loading your module for you to inspect it, ie putting you in the scope of the module. 看起来GHCi正在加载您的模块供您检查,即将您置于模块的范围内。 Two hints at that are the prompt *Hiding> and the fact that you accessed the hidden function. 两个提示是提示*Hiding>以及您访问隐藏功能的事实。

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

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. 如果你试图从另一个模块引用该模块,我敢打赌hidden拒绝工作。 Could be that GHCI is all-knowing :) 可能是GHCI是全知的:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM