S. Alexander Jacobson writes:
> 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)
Wouldn't it be a great deal less tortuous to define:
> x .++ y = show x ++ y
> x ++. y = x ++ show y
and then to use (++), (.++), or (++.), as appropriate?
> > res = (2+2) ./ " 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.
It took me a little head-scratching to work out why this _isn't_ handled
by numeric defaults (and I'm still not 100% clear what the reason for
the requirement that defaults only resolve "standard" context
ambiguities), but clearly, that wouldn't work for non-numeric types,
which doesn't seem to be as general as you'd like.
> 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.
I'm not sure why you'd want (.) or (..) anyway, but from my (admittedly
limited) experience of Java, I'm truly glad one can't use (+) in this
way...
Slainte,
Alex.