Not in scope data constructor
- Module names start with a capital - Haskell is case sensitive
- Line up your code at the left margin - layout is important in Haskell.
- The bit in brackets is the export list - miss it out if you want to export all the functions, or put everything you want to export in it.
First.hs
:
module First where
type S = SetType
data SetType = S[Integer]
Second.hs
:
module Second where
import First
module first () where
Assuming in reality the module name starts with an upper case letter, as it must, the empty export list - ()
- says the module doesn't export anything, so the things defined in First
aren't in scope in Second
.
Completely omit the export list to export all top-level bindings, or list the exported entities in the export list
module First (S, SetType(..)) where
(the (..)
exports also the constructors of SetType
, without that, only the type would be exported).
And use as
module Second where
import First
foo :: SetType
foo = S [1 .. 10]
or, to limit the imports to specific types and constructors:
module Second where
import First (S, SetType(..))
You can also indent the top level,
module Second where
import First
foo :: SetType
foo = S [1 .. 10]
but that is ugly, and one can get errors due to miscounting the indentation easily.