为什么我可以使用这个“私人”值构造函数? [英] Why can I use this "private" value constructor?
本文介绍了为什么我可以使用这个“私人”值构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
module形状
(Shape(Rectangle)
)其中
data Shape = Circle | Rectangle派生(显示)
然后我进入GHCi并使用加载它: l形状
。
键入 Circle
可以工作。我只在指令中指定了 Rectangle
,所以它为什么会起作用?
解决方案
这是使用:load
的副作用。如果您改用
ghci> :m +形状
或
ghci的>导入形状
您将无法访问 Circle
构造函数。
I put this in Shapes.hs:
module Shapes
( Shape(Rectangle)
) where
data Shape = Circle | Rectangle deriving (Show)
Then I go into GHCi and load it with :l Shapes
.
Typing Circle
works. I only specified Rectangle
in the paranthesis, so why does it work?
解决方案
It's a side effect of using :load
. If you instead used
ghci> :m +Shapes
or
ghci> import Shapes
you wouldn't be able to access the Circle
constructor.
这篇关于为什么我可以使用这个“私人”值构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文