haskus / packages

Haskus packages
https://haskus.org/
24 stars 11 forks source link

Variant/VariantF: Make it possible to derive Data and Generic instances #3

Closed woehr closed 6 years ago

woehr commented 6 years ago

I'm unsure whether this is impossible or just requires modifications on the library side, but deriving standalone instances of Data and Generic doesn't work.

:145:1: error:
    • Can't make a derived instance of ‘Generic (Variant xs)’:
        The data constructors of ‘Variant’ are not all in scope
          so you cannot derive an instance for it
    • In the stand-alone deriving instance for ‘Generic (Variant xs)’
    |
145 | deriving instance Generic (Variant xs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:148:1: error:
    • Can't make a derived instance of ‘Data (Variant xs)’:
        The data constructors of ‘Variant’ are not all in scope
          so you cannot derive an instance for it
    • In the stand-alone deriving instance for
        ‘(Typeable xs) => Data (Variant xs)’
    |
148 | deriving instance (Typeable xs) => Data (Variant xs)
hsyl20 commented 6 years ago

The implementation of Variant uses Any and unsafeCoerce, so I don't see how we could provide these instances without exposing this and making them unsafe/useless. I guess it's another limitation for not having a builtin variant type in GHC.

woehr commented 6 years ago

Thanks for the info.