What is going on here? I'm importing a data constructor, apparently successfully because I don't get an error, but when I try to use the constructor, I get an error saying its not in scope!
In Test.hs
:
import Database.Persist (Key)
main = Key
Result:
$ ghc test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
test.hs:3:8: Not in scope: data constructor `Key'
import Database.Persist (Key)
The above imports a type named Key
but none of its constructors. To import the constructor Key
of the type Key
you need to do
import Database.Persist (Key(Key))
or just
import Database.Persist (Key(..))
to import all constructors of the given type.
In order to import a constructor you must use the following syntax
import Database.Persist (Key (..))
Generally, when importing a type or typeclass by name only the type gets imported. The constructors and member functions must be imported using the Name (..)
or Name (Constructor)
syntax. This is fairly convenient as it's often the case that you need to write a type signature using an imported type even if you don't ever need to construct or examine values of that type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With