Define a module in multiple files

Dear Cafe, Is there a way of splitting the definition of a module into multiple files? Cheers, -- Ozgur Akgun

On Mon, Nov 30, 2009 at 5:15 PM, Ozgur Akgun
Is there a way of splitting the definition of a module into multiple files?
Let's say you have some module A which introduces 3 symbols: module A (a, b, c) where a = 1 b = 2 c = 3 Now we will split it in 3 modules: module B ( b ) where b = 2 module C ( c ) where c = 3 module A (a, b, c) where import B ( b ) import C ( c ) a = 1 You can also do the inverse: create a single module of which parts are exported in multiple other modules. This can be useful to avoid circular dependencies while still presenting a nice interface to your library users.

Nice idea, but this way you still need to modify the single module which
glues them alltogether.
I wanted to allow the users of the module add some functionality to the
module itself.
Thanks for the perspective though,
-- Ozgur
2009/11/30 Roel van Dijk
On Mon, Nov 30, 2009 at 5:15 PM, Ozgur Akgun
wrote: Is there a way of splitting the definition of a module into multiple files?
Let's say you have some module A which introduces 3 symbols:
module A (a, b, c) where a = 1 b = 2 c = 3
Now we will split it in 3 modules:
module B ( b ) where b = 2
module C ( c ) where c = 3
module A (a, b, c) where import B ( b ) import C ( c ) a = 1
You can also do the inverse: create a single module of which parts are exported in multiple other modules. This can be useful to avoid circular dependencies while still presenting a nice interface to your library users.
-- Ozgur Akgun

On Mon, Nov 30, 2009 at 6:27 PM, Ozgur Akgun
Nice idea, but this way you still need to modify the single module which glues them alltogether. I wanted to allow the users of the module add some functionality to the module itself.
I don't think that is possible. But a user could easily create a new module which offers all the functionality of the old one plus the user's own additions. -- Some library module module A (a) where a = 1 -- Custom module written by user module UserModule (module A, myFunction) where import A userPrint = print -- Program which uses UserModule module Main where import UserModule main = userPrint a The idea is that UserModule re-exports all symbols from module A. So importing UserModule brings all symbols from A in scope and possibly extra symbols defined in UserModule itself.
participants (2)
-
Ozgur Akgun
-
Roel van Dijk