Suppose I have a module such as:
module Wibble (Foo) where
data Foo = Bar | Baz
where I have chosen (or forgotten) to export the constructors for Foo.
In some other module, I try to import and use the constructors:
module Main where
import Data.Unit (Unit)
import Effect (Effect)
import Effect.Console (log)
import Wibble (Foo(..))
main :: Effect Unit
main =
let x = Bar
in log "hello"
This, as expected, fails. However, the error message is a little strange. It says
Error found:
in module Main
at src/Main.purs:11:11 - 11:14 (line 11, column 11 - line 11, column 14)
Unknown data constructor Bar
The line reference is to the line containing let x = Bar.
I guess my mental model was that (..) meant all the data constructors associated with that type. Whereas it seems to be that, in the context of an import, (..) means all the constructors that were exported, which is a possibly empty list. And in the context of an export (..) means all the constructors associated with that type.
If I write import Wibble (Foo(..)) and Wibble does not export any constructors for Foo would it be possible to throw an error, or at least a warning?
Or should I just abandon (..) entirely and use named imports and exports for constructors?
Suppose I have a module such as:
where I have chosen (or forgotten) to export the constructors for Foo.
In some other module, I try to import and use the constructors:
This, as expected, fails. However, the error message is a little strange. It says
The line reference is to the line containing let x = Bar.
I guess my mental model was that (..) meant all the data constructors associated with that type. Whereas it seems to be that, in the context of an import, (..) means all the constructors that were exported, which is a possibly empty list. And in the context of an export (..) means all the constructors associated with that type.
If I write import Wibble (Foo(..)) and Wibble does not export any constructors for Foo would it be possible to throw an error, or at least a warning?
Or should I just abandon (..) entirely and use named imports and exports for constructors?