mgsloan / store

Fast binary serialization in Haskell
MIT License
109 stars 35 forks source link

Couldn't match type ‘'False’ with ‘'True’ #141

Closed chrisdone closed 5 years ago

chrisdone commented 5 years ago

It's the same issue I encountered in persist: https://github.com/minad/persist/issues/4

    /home/chris/Work/chrisdone/prana/prana-primops/src/Prana/PrimOp/Type.hs:13:10: error:
        • Couldn't match type ‘'False’ with ‘'True’
            arising from a use of ‘Data.Persist.$dmput’
        • In the expression: Data.Persist.$dmput @(PrimOp)
          In an equation for ‘put’: put = Data.Persist.$dmput @(PrimOp)
          In the instance declaration for ‘Persist PrimOp’
       |
    13 | instance Persist PrimOp
       |          ^^^^^^^^^^^^^^

    /home/chris/Work/chrisdone/prana/prana-primops/src/Prana/PrimOp/Type.hs:13:10: error:
        • Couldn't match type ‘'False’ with ‘'True’
            arising from a use of ‘Data.Persist.$dmget’
        • In the expression: Data.Persist.$dmget @(PrimOp)
          In an equation for ‘get’: get = Data.Persist.$dmget @(PrimOp)
          In the instance declaration for ‘Persist PrimOp’

Here's a gist with a reproducible case:

https://gist.github.com/chrisdone/c908dbdbbeaaa945575ce5be7b47b9a6

I was deriving the type with TH (commented out), but it's reproducible with the derived sum type copy/pasted in.

mgsloan commented 5 years ago

Ah, interesting! This is coming from the general obtuseness of GHC complaining about constraints deep in instance resolution. I've improved the errors in https://github.com/fpco/store/commit/d6bee5a4eab3cbebee9f989d6952f8faf4c23d40 and released as version 0.5.1.1

Error with base>=4.9:

    /home/mgsloan/proj/store/test/Data/HmmSpec.hs:481:10: error:
        • Generic deriving of Store instances can only be used on datatypes with fewer than 256 constructors.
        • In the expression: store-0.5.1.0:Data.Store.Impl.$dmsize @PrimOp
          In an equation for ‘size’:
              size = store-0.5.1.0:Data.Store.Impl.$dmsize @PrimOp
          In the instance declaration for ‘Store PrimOp’
        |
    481 | instance Store PrimOp
        |          ^^^^^^^^^^^^

    /home/mgsloan/proj/store/test/Data/HmmSpec.hs:481:10: error:
        • Generic deriving of Store instances can only be used on datatypes with fewer than 256 constructors.
        • In the expression: store-0.5.1.0:Data.Store.Impl.$dmpoke @PrimOp
          In an equation for ‘poke’:
              poke = store-0.5.1.0:Data.Store.Impl.$dmpoke @PrimOp
          In the instance declaration for ‘Store PrimOp’
        |
    481 | instance Store PrimOp
        |          ^^^^^^^^^^^^

    /home/mgsloan/proj/store/test/Data/HmmSpec.hs:481:10: error:
        • Generic deriving of Store instances can only be used on datatypes with fewer than 256 constructors.
        • In the expression: store-0.5.1.0:Data.Store.Impl.$dmpeek @PrimOp
          In an equation for ‘peek’:
              peek = store-0.5.1.0:Data.Store.Impl.$dmpeek @PrimOp
          In the instance declaration for ‘Store PrimOp’
        |
    481 | instance Store PrimOp

Error from before TypeError was a thing:

    /home/mgsloan/proj/store/test/Data/HmmSpec.hs:481:10:
        Could not deduce (store-0.5.1.0:Data.Store.Impl.TypeErrorMessage
                            "Generic deriving of Store instances can only be used on datatypes with fewer than
256 constructors.")
          arising from a use of ‘store-0.5.1.0:Data.Store.Impl.$gdmsize’
        In the expression: store-0.5.1.0:Data.Store.Impl.$gdmsize
        In an equation for ‘size’:
            size = store-0.5.1.0:Data.Store.Impl.$gdmsize
        In the instance declaration for ‘Store PrimOp’
chrisdone commented 5 years ago

:muscle: Nice!