Why can ghci see non-exported types and constructors? How can I fix it?

假装没事ソ 提交于 2019-12-05 11:12:07

Yes, when you load a file in GHCi like that, you can access anything defined in that file regardless of whether or not it is exported. This way expressions you write into GHCi behave exactly like they would inside the loaded file. So you can use GHCi to quickly test an expression that you mean to use inside the file or to quickly test a function defined in the file even if it is private.

If you want the code to behave as if imported from another file, you can use import instead of :l. Then it will only allow access to expported definitions.

If you import a module with :l, you get access to everything, ignoring the export clause:

Prelude Export> :l Export
[1 of 1] Compiling Export           ( Export.hs, interpreted )
Ok, modules loaded: Export.
*Export> a
6
*Export> b
5

If you instead import Export, you get only the exported bindings:

Prelude> import Export
Prelude Export> a
6
Prelude Export> b

<interactive>:28:1: Not in scope: ‘b’
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!