trevor at galois.com
Fri Aug 8 13:59:48 EDT 2008
Here's an example that might help:
> import Data.Typeable
> data Test a = Test Int
> instance Typeable a => Show (Test a) where
> show t@(Test i) = "Test " ++ show (typeOf (ty t)) ++ " " ++ show i
> ty :: Test a -> a,
> ty = undefined
and its use:
*Main> show (Test 10 :: Test Int)
"Test Int 10"
*Main> show (Test 10 :: Test String)
"Test [Char] 10"
On Wed, 2008-08-06 at 19:09 +0100, 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?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080808/157ce00b/attachment.bin
More information about the Haskell-Cafe