TL;DR How to make (Key record) an instance of Eq/Show/Read in Yesod
I'm having a problem with module recursion. I've declared some of my own data types in a file which I want to be available to Models.hs, since I need to use it in the config/models file. But one of the types needs data types from the DB. A FooId (i.e. Key Foo) to be precise.
It looks something like this:
config/models
Foo
name Text
thingy (Bar Foo) Maybe
UniqueName name
deriving Eq Show Read Typeable
My own file contains these
data Bar record = Bar { a :: [Jab record] }
deriving (Eq, Show, Read, Typeable)
data Jab record = Jab { b :: Key record
, c :: Int
}
deriving (Eq, Show, Read, Typeable)
Now I need to import Model.hs to get Key to work, but I also need to import my file into Model.hs for it to work. I've also tried adding my own types to Models.hs, but I get these errors:
Model.hs:24:13:
No instance for (Eq (Key record))
arising from the first field of ‘Jab’ (type ‘Key record’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Eq (Jab record))
And adding a "deriving instance Eq a => Eq (Key a)" together with the {-# LANGUAGE StandaloneDeriving #-} doesn't work either.
If anyone knows how to remedy this, it'd help me immensely.