2014-04-15 79 views
0

我有下面的代碼,我只想從我的模塊中只導出sphereVolume和sphereArea函數。在haskell導入我們自己的模塊

module Geometry 
    (sphereVolume 
    , sphereArea 
    ) where 

sphereVolume :: Float -> Float 
sphereVolume radius = (4.0/3.0) * pi * (radius^3) 

sphereArea :: Float -> Float 
sphereArea radius = 4 * pi * (radius^2) 

cubeVolume :: Float -> Float 
cubeVolume side = cuboidVolume side side side 

cubeArea :: Float -> Float 
cubeArea side = cuboidArea side side side 

cuboidVolume :: Float -> Float -> Float -> Float 
cuboidVolume a b c = rectangleArea a b * c 

rectangleArea :: Float -> Float -> Float 
rectangleArea a b = a * b 

當我在寫ghci的我import Geometry收到以下錯誤

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

我確信他們是在同一個目錄和文件名相同的模塊。我在這裏錯過了什麼?

回答

2

請勿在ghci中輸入import。只需使用普通的

:l Geometry 
3

由於永邦說,你可以使用:l Geometry爲了與GHCI您的代碼工作。但是您可以一次加載一個模塊(使用:l)。如果你已經寫了幾個模塊,你希望能夠同時工作?那麼你需要import他們。

爲了能夠從GHCi內部import Geometry,您需要安裝它。最簡單的方法就是使用cabal。這是guide

相關問題