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

deriveSafeCopy not working for mutual recursive data-types in GHC 9.2.4 #90

Open
marco-comini opened this issue Oct 2, 2022 · 3 comments

Comments

@marco-comini
Copy link

Hi folks, I've just installed GHC 9.2.4 (now that is the recommended versio) and tried to compile one of my projects that is working fine in GHC 8.10.7.

To rule out many details, let's say that I have to define two mutual recursive types TypeA and Type B. With 9.2.4 I get errors that can be abstracted as

Could not deduce (SafeCopy TypeB) ... arising from a use of ‘getSafePut’ ... in
$(deriveSafeCopy 0 'base ''TypeA)

and if I try to swap the order of definitions of TypeA/TypeB I get the dual error message.
Am I missing something new that has to be done with 9.2.4 or is it a bug in deriveSafeCopy?

Thanks in advance for any help.

@ddssff
Copy link
Collaborator

ddssff commented Oct 3, 2022

Can you provide a self contained example of the failure?

@marco-comini
Copy link
Author

marco-comini commented Oct 5, 2022

{-# LANGUAGE TemplateHaskell #-}
import qualified Data.SafeCopy as SC

data A = A B | C
data B = B A

$(SC.deriveSafeCopy 0 'SC.base ''A)
$(SC.deriveSafeCopy 0 'SC.base ''B)

(that also swapping the last two lines gives error)

@stepcut
Copy link
Member

stepcut commented Oct 5, 2022

I ran into the same issue a while ago. I did not keep great notes, but it seemed to me like it was a new restriction in TH. I may or may not have found a relevant bug in the GHC bug tracker. My work-around was to use Generics instead,

#if __GLASGOW_HASKELL >= __900__
instance SafeCopy NavBar where version = 1
instance SafeCopy NavBarItem where version = 1
#else
$(deriveSafeCopy 1 'base ''NavBar)
$(deriveSafeCopy 1 'base ''NavBarItem)
#endif

So, my inclination is to blame GHC 9.2, but it would be nice if someone could figure out what is really happening and if the deriveSafeCopy can be tweaked to handle this situation with GHC 9.2. In the meantime, the Generics work-around seems reasonable. In fact, some might argue that Generics should be preferred over TH anyway. But, I have no idea how they compare performance-wise.

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