1

I’m using the singletons and singletons-th libraries, and I want (if possible) to split a singleton definition between files. I tried creating a data family, but I’m getting a Declaration cannot be promoted error.

data family Field
data family SField :: Field -> Type

singletons
  [d|

  data instance Field = Field1 | Field2
  |]

>>> Other file:
singletons
  [d|
  data instance Field = Field3
  |]

How could I split the singleton definition between two or more files?

David Davó
  • 417
  • 1
  • 4
  • 18

1 Answers1

1

You've got two problems, one of them nothing to do with splitting between files nor TH.

  • "Data family instance constructors cannot be promoted at the moment. GHC’s type theory just isn’t up to the task of promoting data families, which requires full dependent types." says the User Guide I think that explains the cannot be promoted error. So you can't define SField like that.

  • A data family should have a type parameter (same as a class). Something like data family Field a; ... data instance Field Int = ...; data instance Field Char = ...;. Without a parameter, you can define only one instance, and all its constructors would have to be in that instance.

Why is it you're trying to define a data family, and why via TH/what's the use case here?

AntC
  • 2,623
  • 1
  • 13
  • 20
  • The use case is defining a huge singleton, with about 100 singletons split between two modules. I've used a Data family because that's what the library seemed to use, but I'm happy with whatever approach that lets me split the definition between the two modules. – David Davó Jul 29 '21 at 06:25
  • Btw, the data family has a Kind of `Field -> Type`, (or `Field-> * `) so it has a parameter, but is defined in other syntax – David Davó Jul 29 '21 at 07:09
  • Then what does `Field1, Field2, Field3` mean? And why do they have to be defined in separate modules? Whatever your "in other syntax" means, your code doesn't show syntax for a type parameter to the `data family`, so you _don't_ have a parameter. – AntC Jul 29 '21 at 09:38
  • It's true, families can't be promoted (yet) but it's an open issue in GitHub – David Davó Aug 01 '21 at 16:01