acid-state / safecopy

An extension to Data.Serialize with built-in version control
60 stars 37 forks source link

PolyKinds breaks phantom newtype deriving with non obvious error message #83

Open yaitskov opened 3 years ago

yaitskov commented 3 years ago

Hi,

I am upgrading SafeCopy to version 0.10.4.1 and discovered following unpleased behavior. Mostly I concerned with stumbling error message.

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

module Main where

import           Data.SafeCopy
import           Data.Serialize  
import           GHC.Generics 
import           Type.Reflection 
import           Prelude

newtype IntKey r = IntKey { intKey :: Int } deriving (Show, Eq, Generic, Serialize, Typeable)

instance Typeable r => SafeCopy (IntKey r)

The snipped above is just fine until I enable PolyKinds extension. Error message makes impression like GHC is incapable to do the obvious thing!

    • Could not deduce (Typeable k)
        arising from the superclasses of an instance declaration
      from the context: Typeable r
        bound by the instance declaration
        at Main.hs:31:10-43
    • In the instance declaration for ‘SafeCopy (IntKey r)’
   |
31 | instance Typeable r => SafeCopy (IntKey r)
stepcut commented 3 years ago

Does this code work with PolyKinds enabled in older versions of safecopy ?

From your report it is not clear if it used it work in older version of safecopy, and upgrading broke things.

ddssff commented 3 years ago

Not surprisingly, this works: instance Typeable (r :: *) => SafeCopy (IntKey r), I can't think of a way to do this in the library code off the top of my head. I does seem my version bump was too optimistic.