Quantcast

Is it possible to export module aliases?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is it possible to export module aliases?

Brian Hulley
Hi -
Given some large list of modules which need to be used qualified, I'd like
to be able to make a convenience module that I could use instead, and which
would export all these modules also qualified by an alias, ie:

module Top
       ( module qualified Top.First as First
       , module qualified Top.Second as Second
       ) where ...
import qualified Top.First

so that I could then say:

import Top

main = do
   a <- First.create ...
   b <- Second.create ...

instead of having to always write:

import qualified Top.First as First
import qualified Top.Second as Second
-- this may be a *very* long list

in every module that uses the "Top" API.

The current "workaround" for this problem in the standard libraries seems to
be to always append the module name to the name of the function or type or
constructor (which is unfortunately, like record field names, not local to
the type but that's another story) eg by using createFirst, createSecond
etc, which seems a bit messy to me.

An alternative is to use the C preprocessor and #include a file containing
all the import declarations, but although "ok", I'd prefer to be able to
express the code organization purely in Haskell itself.

This must be a very common issue so I'm wondering if anyone else has some
better ideas on how to solve it?

Thanks, Brian.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Is it possible to export module aliases?

Simon Peyton Jones
Are you asking for the same thing as described under "Permit qualified
exports" on this Haskell Prime page?

       
http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/ModuleSyst
em

Simon

| -----Original Message-----
| From: [hidden email]
[mailto:[hidden email]] On Behalf Of
| Brian Hulley
| Sent: 27 April 2006 02:51
| To: Haskell-cafe
| Subject: [Haskell-cafe] Is it possible to export module aliases?
|
| Hi -
| Given some large list of modules which need to be used qualified, I'd
like
| to be able to make a convenience module that I could use instead, and
which
| would export all these modules also qualified by an alias, ie:
|
| module Top
|        ( module qualified Top.First as First
|        , module qualified Top.Second as Second
|        ) where ...
| import qualified Top.First
|
| so that I could then say:
|
| import Top
|
| main = do
|    a <- First.create ...
|    b <- Second.create ...
|
| instead of having to always write:
|
| import qualified Top.First as First
| import qualified Top.Second as Second
| -- this may be a *very* long list
|
| in every module that uses the "Top" API.
|
| The current "workaround" for this problem in the standard libraries
seems to
| be to always append the module name to the name of the function or
type or
| constructor (which is unfortunately, like record field names, not
local to
| the type but that's another story) eg by using createFirst,
createSecond
| etc, which seems a bit messy to me.
|
| An alternative is to use the C preprocessor and #include a file
containing
| all the import declarations, but although "ok", I'd prefer to be able
to
| express the code organization purely in Haskell itself.
|
| This must be a very common issue so I'm wondering if anyone else has
some
| better ideas on how to solve it?
|
| Thanks, Brian.
|
| _______________________________________________
| Haskell-Cafe mailing list
| [hidden email]
| http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is it possible to export module aliases?

Brian Hulley
Simon Peyton-Jones wrote:
> Are you asking for the same thing as described under "Permit qualified
> exports" on this Haskell Prime page?
>
>
> http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/ModuleSystem

Yes - thanks for pointing out this section of the proposal.
I think it would be very useful indeed, because I'm finding that the use of
qualified imports in my code is essential to avoid name clashes and also
helps with consistent naming for functions.
It also allows more freedom in choosing value constructors and record field
names without worrying about name clashes or having to prepend the name of
the type to everything.

As an aside, an alternative to the second point would be to make value
constructors and field names local to their type so that

    data T = Foo{field::Int}

would introduce the following:

    T, T^Foo, T^field        -- top level names

    -- a global type class
    class (.field) a b | a -> b where
           (.field) :: a -> b

     -- a local instance
     instance T (.field) where
          (.field) Foo{field=f} = f

and type inference could allow the use of plain Foo and field only when the
type at that location was known to be T (eg making use of user-supplied top
level type annotations) but this would require some major changes to the way
type inference is done so it's probably not possible for Haskell'.

Regards, Brian.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Loading...