[Haskell-cafe] GADT and instance deriving

TP paratribulations at free.fr
Sat May 25 00:45:58 CEST 2013


Alexander Solla wrote:

>> (Do you confirm that tilde in s~s1 means "s has the same type as s1"? I
>> have
>> not found this information explicitly in the Haskell stuff I have read).
>>
> 
> Yes.
> 
> http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/equality-constraints.html
> 
> Is this (Typeable) the right way to go? Is there any other solution?
>>
> 
> Using typeable is a perfectly reasonable way to go.

Thanks for your help.
Unfortunately, I am in the following case (in my real code, not the dummy 
example of my initial post):

http://haskell.1045720.n5.nabble.com/Can-t-make-a-derived-instance-of-Typeable-A-B-A-has-arguments-of-kind-other-than-td3121994.html

Indeed, I obtain at compilation:

Can't make a derived instance of `Typeable (Tensor ($a))':
      `Tensor' must only have arguments of kind `*'

"Tensor" is a type constructor which takes a type-level integer as argument 
to make a concrete type "Tensor order" (so its kind is Nat -> *).
Thus in my real code, I cannot derive the typeable instance automatically. I 
am compelled to write an instance of typeable for my GADT. Are there some 
tutorial around here? Because the documentation page is a bit terse for my 
level of knowledge:

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Typeable.html

In the first link above, someone writes:

"""
You'll have to manually
write a Typeable instance if you want one.  The process is somewhat
trickier than you might expect, due to the fact that Typeable does
some unsafe stuff.  But there are plenty of examples for how to do it
safely. 
"""

Where are these examples that can help me to write my instance?
I have tried to read the source of the implemented instances in 
data.typeable, not so easy for me.

Thanks,

TP




More information about the Haskell-Cafe mailing list