3

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.

Vanson Samuel
  • 1,953
  • 2
  • 17
  • 30
  • 2
    Note that "Cannot find _type of_ method X" does not mean that it is X which is missing. The error itself is reported from [here](https://github.com/goldfirere/singletons/blob/master/src/Data/Singletons/Single.hs#L453). Looks like something else is missing which prevents `dsReify` to find the type. As a wild guess I'd assume `Nat` but I don't see it exported as well (I have not tried it). – max630 Dec 29 '18 at 21:02

1 Answers1

2

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"

max630
  • 8,762
  • 3
  • 30
  • 55