DeriveAnyClass fails to derive some classes
{-# LANGUAGE DeriveAnyClass, DeriveGeneric #-}
import Database.PostgreSQL.Simple
import GHC.Generics
data Foo = Foo { bar :: Int }
deriving (Generic, ToRow)
This succeeds using ghci
, but fails when trying to compile it using ghc
with the following error message:
• No instance for (ToRow Int)
arising from the first field of ‘Foo’ (type ‘Int’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
• When deriving the instance for (ToRow Foo)
However, it works if I use instance ToRow Foo
instead of relying upon DeriveAnyClass
.
I've tried this with other types instead of Int
, using newtype
instead of data
and having multiple fields in the datatype.