[Haskell-beginners] Comfortable handling of module hierarchies

damodar kulkarni kdamodar2000 at gmail.com
Sun Sep 16 12:37:41 CEST 2012


Do you know any document pointing out the rationale behind this decision
about modules taken by the Haskell designers?

Thanks.
-Damodar

On Sat, Sep 15, 2012 at 9:30 PM, Karl Voelker <ktvoelker at gmail.com> wrote:

> On Fri, Sep 14, 2012 at 6:23 PM, Christopher Howard
> <christopher.howard at frigidcode.com> wrote:
> >
> > import qualified Plant as P
> >
> > P.Fruit.Raspberry.jam
>
> Short answer: P.Fruit.Raspberry.jam would work if you said:
>
> import qualified Plant.Fruit.Raspberry as P.Fruit.Raspberry
>
> Long answer:
>
> You can't have exactly what you want because the Haskell module
> namespace isn't exactly heirarchical. Here's an excerpt from the
> Haskell 98 report [1]:
>
> "The name-space for modules themselves is flat, with each module being
> associated with a unique module name (which are Haskell identifiers
> beginning with a capital letter; i.e. modid)."
>
> Notice that this doesn't allow for dots in module names. A
> commonly-provided language extension allowed dots in module names, and
> compilers took these dots as a signal to look for a module's source at
> a particular place in the directory tree, but the semantics of the
> language didn't have a heirarchy of modules.
>
> Things haven't changed much in Haskell 2010, other than the existing
> use of dots being formalized [2]:
>
> "Module names can be thought of as being arranged in a hierarchy in
> which appending a new component creates a child of the original module
> name. For example, the module Control.Monad.ST is a child of the
> Control.Monad sub-hierarchy. This is purely a convention, however, and
> not part of the language definition; in this report a modid is treated
> as a single identifier occupying a flat namespace."
>
> In your code snippet, P.Fruit.Raspberry doesn't work because although
> P refers to the same module as Plant, there isn't anything "inside" P
> (or Plant) called Fruit.Raspberry.
>
> -Karl
>
> [1] http://www.haskell.org/onlinereport/modules.html
> [2]
> http://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-980005
>
> _______________________________________________
> 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/20120916/bb143a37/attachment.htm>


More information about the Beginners mailing list