TemplateHaskell seems to not be reporting what function it needs to be imported

Viewed 103

This import:

 import Data.Singletons.TH
   (
     FalseSym0,
     FromEnum,
     MaxBound,
     MinBound,
     PEq,
     PShow,
     ShowsPrec,
     ShowStringSym0,
     SShow,
     ToEnum,
     TrueSym0,
     sShowsPrec,
     sShowString
   )

fails with the following error:

 error:
         Cannot find type of method Data.Singletons.Prelude.Enum.toEnum
        |
     23 | $(singletons [d|
        |   ^^^^^^^^^^^^^^...

 error: Q monad failure
        |
     23 | $(singletons [d|
        |   ^^^^^^^^^^^^^^...

When the import is changed to:

 import Data.Singletons.TH

everything works just fine.

Adding toEnum to the import list for Data.Singletons.TH will fail with:

 error:
         Module ‘Data.Singletons.TH’ does not export ‘toEnum’
        |
     21 |     toEnum
        |     ^^^^^^

From what I can tell the part of the code the caused this is here:

 $(singletons [d|
   data DoorState :: Type where
     Opened :: DoorState
     Closed :: DoorState
     Locked :: DoorState
     deriving (Bounded, Data, Enum, Eq, Show, Typeable)
   |])

 $(singletons [d|
   class Cycle a where
     next :: a -> a
     prev :: a -> a
   |])

 instance forall a. (Bounded a, Enum a, Eq a) => Cycle a where
   next x
     | x == maxBound = minBound
     | otherwise = succ x
   prev x
     | x == minBound = maxBound
     | otherwise = pred x

What is the function that actually needs to be added to the import list for everything to work correctly? Why is this function not being reported in the error message.

1 Answers

Apparently you can get the answer to your question by passing the full import and adding "-ddump-minimal-imports" to the compilation options. In your case you are missing (for lts-13.0): "sError, Sing(SFalse, STrue), PEnum(..), SEnum(..), type (==@#@$), SEq((%==)), ErrorSym0"

Related