Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not in scope data constructor

Tags:

I have two .hs files: one contains a new type declaration, and the other uses it.

first.hs:

module first () where
    type S = SetType
    data SetType = S[Integer]  

second.hs:

module second () where
    import first 

When I run second.hs, both modules first, second are loaded just fine.

But, when I write :type S on Haskell platform, the following error appears

Not in scope : data constructor 'S'

Note: There are some functions in each module for sure, I'm just skipping it for brevity

like image 219
Shimaa Avatar asked Nov 20 '12 20:11

Shimaa


1 Answers

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.

like image 61
Daniel Fischer Avatar answered Sep 18 '22 14:09

Daniel Fischer