I have a simple definition for a Nat and a definition for types indexed by Nat's, Natty.
data Nat :: * where
Zero :: Nat
Suc :: Nat -> Nat deriving(Show, Typeable)
data Natty :: Nat -> * where
Zy :: Natty Zero
Sy :: Natty n -> Natty (Suc n) deriving Typeable
I want to store and manipulate these Natty's in a generic fashion with the use of the Type.Reflection module.
Storing as a Nat as a type rep works fine.
foo :: Nat -> SomeTypeRep
foo x = SomeTypeRep (typeOf x)
But storing a Natty as a type rep doesn't work unless extra constraints are added.
boo :: Natty n -> SomeTypeRep
boo x = SomeTypeRep (typeOf x)
boo produces the following error:
No instance for (Typeable n) arising from the use of 'typeOf'
My question is why can Haskell not recognise that n is a nat and should therefore be Typeable?
Like I said I can fix this issue by adding the constraint of Typeable n to the beginning of boo but when I'm using a function that returns natty in the middle of another function its not that simple.
The following extensions and imports have been used.
{-# LANGUAGE DataKinds, KindSignatures, GADTs #-}
import Type.Reflection