2014-05-02 67 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'。 –