Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

• Couldn't match type ‘'False’ with ‘'True’ #4

Closed
chrisdone opened this issue May 18, 2019 · 4 comments
Closed

• Couldn't match type ‘'False’ with ‘'True’ #4

chrisdone opened this issue May 18, 2019 · 4 comments

Comments

@chrisdone
Copy link

chrisdone commented May 18, 2019

Hey,

I thought you might find this error message interesting if not helpful:

    /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’

I'm gonna try the flat package, as I really just want a trivial serialization that's more efficient than binary and doesn't take 10 minutes to build like store. 🤷‍♂️

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.

Good luck! 👍 😄

@minad
Copy link
Owner

minad commented May 19, 2019

This is a known issue if you have too many constructors. Can you write a manual instance for PrimOp via the Word16 instance? Not via generics. Where did you use TH? (got you - these deriveprimthing, not relevant to this issue)

EDIT: @chrisdone I want to expand a bit on my comment. I tend to close this issue as wontfix, since it is only triggered by the uncommon case of ADTs with more than 256 constructors. This is due to encoding of the tag as 8 bit. In this case of an enum ADT the solution is manual encoding via Word16.

instance Persist PrimOp where
  put = put @Word16 . fromIntegral . fromEnum
  get = do
    x <- toEnumMay . fromIntegral <$> get @Word16
    maybe (fail "Invalid PrimOp") pure x

Please let me know if it is ok for you like this. I think persist is a good solution for your problem. It is as simple and small as things can get, like a stripped down store and faster compilation than flat, which focuses more on compact bitwise packing.

More problematic cases would involve ADTs, which are not enums, with more than 256 constructors. For those it would be worth fixing the issue to take advantage of generics.

@chrisdone
Copy link
Author

Thanks @minad. Good to know.

@mgsloan
Copy link

mgsloan commented May 21, 2019

@minad Note that it is possible to have better error messages for this - see discussion here and patch here.

@minad
Copy link
Owner

minad commented May 21, 2019

@mgsloan Thanks! I will add this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants