On Nov 6, 2007 12:03 PM, Thomas Schilling <[EMAIL PROTECTED]> wrote:
> 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 | <x's type is an instance of Show> = 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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to