2014-05-02 70 views
2

我把这个~/Desktop/Shapes.hs为什么我不能导入此哈斯克尔模块?

module Shapes 
(Shape(Rectangle) 
) where 

data Shape = Circle | Rectangle deriving (Show) 

然后我做到这一点:

cd ~/Desktop 
ghci 

ghci> :m +Shapes 

<no location info>: 
    Could not find module `Shapes' 
    It is not a module in the current program, or in any known package. 

ghci> import Shapes 

<no location info>: 
    Could not find module `Shapes' 
    It is not a module in the current program, or in any known package. 

为什么我得到这个错误?

我也试图与ghc -c Shapes.hs第一编译。它仍然不起作用。

我安装在我的OS X 10.9.2小牛从haskell.org的 “哈斯克尔平台2013.2.0.0为Mac OS X,64位”。我也遵循他们的ghc-clang-wrapper说明。

更新:

有人建议做:l Shapes.hs第一。问题是,:l Shapes.hs加载整个形状文件,这意味着我可以访问Circle值构造函数,即使我没有导出它。见我刚才的问题:Why can I use this "private" value constructor?我想加载只有模块。这可能吗?

回答

5

您需要通过:l Shapes.hs加载您Shapes.hs第一。

  1. 因为你Shapes还没有被加载,所以:m Shapes将无法​​正常工作。

  2. 因为Shapes不存在ghci可以找到的编译软件包,所以import Shapes将不起作用。

如果只想范围导出的符号,:load模块后,您可以使用:moduleimport只导入这些符号。例如,在:load Shapes.hs:module Shapes,Rectangle将在范围之内但Circle不会。

请参见:
What's really in scope at the prompt?
:module and :load

+0

我已经更新了我的问题有这个问题。 – stackoverflowuser

+2

@stackoverflowuser首先':加载Shapes.hs',然后':模块Shapes'。 –