[Haskell-beginners] Using GHCi, import submodule that needs to import another submodule?

David McBride toad3k at gmail.com
Wed Mar 5 18:25:48 UTC 2014


If you want a source file to have a module Geometry.Cuboid, it should be in
a directory named Geometry and the file will have the name of Cuboid.hs.
In order to load that you have to start ghci in the directory that contains
the Geometry directory, not in the one that contains the source file.

So cd .., ghci Geometry/Cuboid.hs


On Wed, Mar 5, 2014 at 1:07 PM, James Toll <james at jtoll.com> wrote:

> 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
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140305/eed84bb9/attachment.html>


More information about the Beginners mailing list