Skip to content

Importing constructor of associated data type fails

I will base my description on the code you find when searching for "instance PersistEntity" on http://www.yesodweb.com/book/persistent. In summary, the code looks like

instance PersistEntity Person where
...
    data EntityField Person typ where
        PersonId   :: EntityField Person PersonId
        PersonName :: EntityField Person String
        PersonAge  :: EntityField Person Int
...

This code is generated from TH (see above). I have not tested if it matters that it is generated. A first step could be to test if manually replacing the TH part yields different results.

The problem is: When i add this code in one module, do not create an export list for that module, and try to import the constructors explicitly (i.e. with a list) in a different module, it does not work.

I read and tried to follow the description on https://wiki.haskell.org/GHC/Type_families, chapter 4.3.

Testcase 1

(not really expected to work; still intersting error message)

import MyModuleContainingInstancePerson ( PersonId )

ghc says

      ‘PersonId’ is a data constructor of ‘EntityField’
    To import it use
      ‘import’ MyModuleContainingInstancePerson( EntityField( VersionVersion ) )
    or
      ‘import’ MyModuleContainingInstancePerson( EntityField(..) )

Testcase 2

(no export list in MyModuleContainingInstancePerson)

import MyModuleContainingInstancePerson ( EntityField(..) )

ghc says

Module ‘MyModuleContainingInstancePerson’ does not export ‘EntityField(..)’

Testcase 3

But when i do provide an export list in MyModuleContainingInstancePerson, like

module MyModuleContainingInstancePerson ( Person(..), EntityField(..) ) where ..

Testcase 2 suddenly works.

Trac metadata
Trac field Value
Version 7.8.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information