I would like to avoid using show all the time for printing strings e.g.
> val = "the sum of 2 and 2 is "++(show $ 2 + 2)++" whenever."
I would prefer to type something like:
> val = "the sum of 2 and 2 is "./(2+2)./" whenever."
> -- i can' find a better haskell compatible operator
I can't simply "show" the arguments of (./) because showing strings adds
quotation marks which I don't want in this context.
So I tried creating my own Stringable class:
> class Stringable a where
> toString::a -> String
> (./) :: (Stringable a,Stringable b)=> a->b->String
> x./y = (toString x)++(toString y)
The trouble is that when I try doing things like:
> res = (2+2) ./ " hello"
I get an "Unresolved top-level overloading" error.
But this works
> i::Int
> i = 2+2
> res = i ./ "hello"
Is there any way to convince Haskell to just resolve these numbers to
SOMETHING by default? Then I can just declare that type an instance of
Stringable.
Ideally, I would prefer to be able to use a more natural string
concatenation operator for this like (.) (..) or, ideally, (+), but I
guess that is not possible.
-Alex-
___________________________________________________________________
S. Alexander Jacobson i2x Media
1-212-697-0184 voice 1-212-697-1427 fax