[Haskell-cafe] [template haskell] Sharing names between constructors and types

Patrick L Redmond plredmond at ucsc.edu
Thu May 19 22:11:12 UTC 2022

I worked around the issue. Apologies for the noise.

I'm still learning, but I think the reason for this error is:

  * The name passed to `voidType` contains module information, and
possibly other information.
  * By reusing the name in the output of `voidType` (as a type) we are
incorrectly overriding the existing name (of a constructor), even
though they're ostensibly different namespaces.

A workaround is to perform `mkName $ nameBase n` inside `voidType`.

On Thu, May 19, 2022 at 1:15 PM Patrick L Redmond <plredmond at ucsc.edu> wrote:
> Hello Haskell Cafe,
> When can a type not share the name of a constructor?
> Defining a type and a constructor with the same name, manually, as
> follows, seems to be acceptable:
>     data F = F | T
>     data T
> However, if the type is generated by Template Haskell, it is no longer
> acceptable, as follows:
>     voidType :: Name -> DecsQ
>     voidType n = do
>         d <- dataD (return []) n [] Nothing [] []
>         return [d]
> In a separate module:
>     data F = F | T
>     $(voidType 'T)
> This will result in a "Multiple declarations of ‘T’" error. Is this expected?
> Thank you,
> Patrick

More information about the Haskell-Cafe mailing list