[Haskell-beginners] Using GHCi, import submodule that needs to import another submodule?
James Toll
james at jtoll.com
Wed Mar 5 18:07:33 UTC 2014
Hi,
I am trying to figure out how to import one submodule from a hierarchical module in GHCi. For example, at the end of Chapter 6 of LYAHFGG (page 106-107), there's an example of a hierarchical module. Or at the bottom of this page, http://learnyouahaskell.com/modules
If I recreate that module on my system and try to import, this is the output:
[~/Geometry]$ ls
Cube.hs Cuboid.hs Sphere.hs
[~/Geometry]$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Geometry.Sphere
<no location info>:
Could not find module `Geometry.Sphere'
It is not a module in the current program, or in any known package.
Prelude> :set -iGeometry
Prelude> import Geometry.Sphere
<no location info>:
Could not find module `Geometry.Sphere'
It is not a module in the current program, or in any known package.
Prelude> :load Sphere
[1 of 1] Compiling Geometry.Sphere ( Sphere.hs, interpreted )
Ok, modules loaded: Geometry.Sphere.
*Geometry.Sphere> :load Cube
Cube.hs:6:18:
Could not find module `Geometry.Cuboid'
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Prelude> :load Cuboid
[1 of 1] Compiling Geometry.Cuboid ( Cuboid.hs, interpreted )
Ok, modules loaded: Geometry.Cuboid.
*Geometry.Cuboid> :load Cube
Cube.hs:6:18:
Could not find module `Geometry.Cuboid'
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Prelude>
So I can't just "import Geometry.Sphere", and I tried setting -i, but that doesn't seem to help. Instead I have to ":load Sphere". Fine, but then when I try to ":load Cube", it fails because of the line in Cube.hs that imports Geometry.Cuboid. Even if I load Geometry.Cuboid first and then try to load Geometry.Cube, it still fails.
So, in GHCi, how do I successfully import a submodule that needs to import some other submodule in the module?
Thanks,
James
More information about the Beginners
mailing list