
6 Nov
2007
6 Nov
'07
2:08 p.m.
On Nov 6, 2007 12:03 PM, Thomas Schilling
On Tue, 2007-11-06 at 09:18 -0500, Graham Fawcett wrote:
Hi folks, Is there a way to declare a 'toString' function, such that toString x | <x is a String> = x toString x |
= show x I think the simpler solution (for your particular problem) is to tag strings that should be printed as-is: newtype Literal = Literal String instance Show Literal where show (Literal x) = x lit :: String -> Literal lit = Literal
I almost replied to ask, "doesn't that solve a different problem?" But I see that in practice, it leads to a similar result, and without type-system trickery. The type-system trickery is still devilishly interesting, though. ;-) Thanks, G