Lysxia / generic-data

Generic data types in Haskell, utilities for GHC.Generics
https://hackage.haskell.org/package/generic-data
MIT License
44 stars 9 forks source link

Strange internal type errors with Coercible #8

Closed Lysxia closed 6 years ago

Lysxia commented 6 years ago

(A really brief note about the issue, to be expanded later.)

For some reason these two lines are different (they shouldn't have to be)

https://github.com/Lysxia/generic-data/blob/ac3651d3a35f3a8e652f474c482251e6cc3fe622/src/Generic/Data/Internal/Surgery.hs#L365

https://github.com/Lysxia/generic-data/blob/ac3651d3a35f3a8e652f474c482251e6cc3fe622/src/Generic/Data/Internal/Surgery.hs#L410

And the compiler doesn't like when I try to put them in a type synonym (RmvConstr, InsConstr or ConstrSurgery).

Even in the current state some tests fail to type check on GHC 8.0 and I cannot explain why:

https://github.com/Lysxia/generic-data/blob/ac3651d3a35f3a8e652f474c482251e6cc3fe622/test/surgery.hs#L63-L72

/home/sam/code/haskell/gdata/test/surgery.hs:66:49: error:
    • Couldn't match representation of type ‘Int’
                               with that of ‘M1
                                               C
                                               ('MetaCons "B" 'PrefixI 'False)
                                               (M1
                                                  S
                                                  ('MetaSel
                                                     'Nothing
                                                     'NoSourceUnpackedness
                                                     'NoSourceStrictness
                                                     'DecidedLazy)
                                                  (K1 GHC.Generics.R Int))
                                               ()’
        arising from a use of ‘removeConstr’

These are coercible: a manually written specialization of coerce at those types type checks.

-- both ways
> coerce (coerce (3 :: Int) :: M1 C ('MetaCons "B" 'PrefixI 'False) (M1 S ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (K1 R Int)) x) :: Int
3
Lysxia commented 6 years ago

This was in commit ac3651d.

A minimal example of the symmetry bug is [here] (https://gist.github.com/Lysxia/f082a3af9472511b5dcec045f945348b), and seems to already be fixed in 8.4.

The other bugs somehow go away by removing the x from the Coercible constraints (commit d8e5d0c) (but putting the x back should reproduce the error).