I’m having trouble deriving a Typeable1 instance for a date structure in Haskell.
This is my code:
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
import Data.Typeable (Typeable,Typeable1)
newtype FooM m a = Foo { unFoo :: (a -> Bar m) -> Bar m }
newtype Bar m = Atom (m (Maybe (Bar m)))
type Baz m = Waldo (FooM m ())
type Waldo a = a
data Qux m = Qux {
baz :: Baz m
, num :: Int
} -- deriving Typeable1 [1]
-- deriving instance Typeable1 Qux [2]
Uncommenting the first comment [1] gives this error:
Cannot derive well-kinded instance of form `Typeable1 (Qux ...)'
Class `Typeable1' expects an argument of kind `* -> *'
In the data type declaration for `Qux'
And uncommenting [2] gives this error:
Kind mis-match
The first argument of `Typeable1' should have kind `* -> *',
but `Qux' has kind `(* -> *) -> *'
In the stand-alone deriving instance for `Typeable1 Qux'
My question is: How can I add a Typeable/Typeable1 instance of Qux, please?
You can’t make
Quxan instance ofTypeable1, but in modern GHC, you should be able to derive an instance ofTypeable, which is now kind-polymorphic enough to handle such higher-kinded types, makingTypeable1and its ilk unnecessary.Outdated answer, kept because it was the accepted answer when the question was asked: Unfortunately, you can’t: the
Typeablehierarchy doesn’t have any typeclasses for things of kind(* -> *) -> *. This may be fixed at some future time now that GHC is starting to support kind polymorphism.