[Haskell-cafe] restricted existential datatypes

Roberto Zunino zunino at di.unipi.it
Wed Jan 10 15:56:14 EST 2007


Misha Aizatulin wrote:

>   The question I'd like to ask is whether there is some trickery to
> circumvent this problem. In the f function I'd like to be able to hint
> to the compiler that I want Show to be derived from cxt which is
> attached to the Box, but I see no way of doing that.

An explicit way of pointing at the dictionary is possible using GADT:

data ShowCxt a where
     Sh :: Show a => ShowCxt a

f :: forall cxt . (Contains cxt ShowCxt) => Box cxt -> String
f (Box (x :: a)) = case subDict (dict :: cxt a) of Sh -> show x

The above compiles in GHC HEAD (6.6 is unfortunately not enough).

Regards,
Zun.


More information about the Haskell-Cafe mailing list