开发者

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.

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)


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


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜