views:

100

answers:

2

Hello,

Im writing app in haskell and I would like to export some functions and datatypes to other files and then be able to use them in my main file.

How to do this ?

thanks for help

+3  A: 

The Wikibooks page on Haskell modules would be a good starting point, or the relevant section of Learn You a Haskell (especially the "Making our own modules" part).

Travis Brown
+5  A: 

You could lay out your source code like so:

Main.hs
A/Module.hs

You need to specify in A/Module.hs which module it actually is; it has to be:

module A.Module where

...

In Main.hs, you import A.Module; all names are exported by default.

Jason Dusek
But in Haskell module names don't *have* to match file names in the same sense that a Java class `com.example.Service` *has* to be in `com/example/Service.java`. Individual compilers can establish conventional correspondences for the sake of convenience, but you could also tell GHC (for example) to find `MyModule` in `SomeRandomDirectory/NotMyModule.hs` if you really wanted to, and (more typically) your `Main` module doesn't have to live in a file named `Main.hs`.
Travis Brown
That's true; you can break from convention if you want to. It's not uncommon to see Cabal project directories that have `src/A/Module.hs`.The more sophisticated redirects that you suggest, I've never tried.
Jason Dusek