1
votes

I created a small module and I want to use it in my program. I’m able to import it in the program and use it. However, I’m not able to import it in ghci. This is causing a lot of problems as I’m not able to test things interactively which I’d like to.

Essentially, I’m creating Geometry.hs from here (http://learnyouahaskell.com/modules#making-our-own-modules) and trying to import it in my program which works. If I do the same thing in ghci, it doesn’t. I run ghci from the same directory where Geometry.hs is present.

This is my program.

import Geometry
main = putStrLn $ show $ Geometry.sphereVolume 1

I try to execute the same lines in ghci and get this error -

<no location info>:
    Could not find module `Geometry'
    It is not a module in the current program, or in any known package.
1
First of all, putStrLn . show is the same as print. Are you typing import into GHCi directly using import Geometry? The :load (or just :l) command is usually used to load local source files. - bheklilr
thanks a lot for your comment. That indeed was the solution to my problem. - shashydhar
@shashydhar: More details can be found at haskell.org/ghc/docs/latest/html/users_guide/…. - Zeta

1 Answers

1
votes

Just so that we keep our answered questions ratio high on the Haskell tag, the solution was to use the :load or :l directives in GHCi to load the source file in the current directory. As @Zeta notes, the documentation with more details can be found at http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#ghci-scope