While modifying :print to further* show the representation of things,
I got stuck at reconstructing dictionaries and the data constructors generated by GHC.

For the purpose of experimenting I am using a simple GADT to embed a dictionary in a value:

data Dict a where
  DictEq  :: Eq x  => x -> Dict x
  DictOrd :: Ord x => x -> Dict x
  DictNum ...

GHC generates a type for e.g. the Eq type class called
:TEq, which contains a single datacon :Deq of type

:Deq :: (a -> a -> Bool) -> :TEq a

In the simple case of Eq this type matches the dictionariess that
GHC embeds in DictEq values.

However, for type classes with one or more superclasses,
it looks like the types of the datacons generated don't carry the context (but of course the dictionaries themselves do carry the dictionaries for the context).

E.g., the type below is generated for :DNum, the datacon of a Num dictionary.
At least, this is what :print obtains from a tcLookupDatacon on :DNum.

:DNum ::                (a -> a -> a)
                     -> (a -> a -> a)
                     -> (a -> a -> a)
                     -> (a -> a)
                     -> (a -> a)
                     -> (a -> a)
                     -> (GHC.Integer.Integer -> a)
                     -> (GHC.Num.:TNum) a)

There is one element for every function in Num.
But where did the dictionaries for the (Eq a, Show a) context go ?
Let's use a DictNum value instantiated to Integer to observe
the dictionary created:

> let d = Dict 1
> :print d
d = DictNum (GHC.Num.:DNum (GHC.Base.:DEq <function> <function>)
(GHC.Show.:DShow <function> <function> <function>) <function> <function> <function> <function> <function> (_t63::t1111) (_t64::t1111))
           1

The dictionary datacon is :DNum and it is indeed carrying the two superclass dictionaries.
Is the type of :DNum lying ?
or What am I missing ?

Thanks,
pepe


* - it used to hide extra arguments of data constructors, such as extra unboxed things or
dictionaries, but that gives some problems

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to