[Haskell-cafe] Phantoms
Henning Thielemann
lemming at henning-thielemann.de
Fri Aug 8 14:58:21 EDT 2008
On Wed, 6 Aug 2008, Andrew Coppin wrote:
> I just (re)discovered that I can do things like
>
> data Foo x = Foo Int Int
>
> Now "Foo Int" and "Foo Double" are, as far as the type checker cares,
> two completely different types, even though in fact they are the same.
> This is actually Quite Useful, in the particular case I'm working on.
>
> Here's the thing though... How do I get it so that "Foo Int" and "Foo
> Double" produce slightly different strings when printed?
The non-hacky Haskell 98 solution is:
class ShowPhantom a where
showPhantom :: Foo a -> String
You can call this from the 'show' implemention for 'Foo a'.
More information about the Haskell-Cafe
mailing list