[mercury-users] String concatenation

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Apr 22 03:30:05 AEST 1999


On 21-Apr-1999, Ralph Becket <rwab1 at cam.sri.com> wrote:
> Just a thought, but it'd be very nice to have +/2 overloaded for strings.

An infix string concatenation operator is certainly a very good idea;
we (the Mercury designers) discussed this quite some time ago
and agreed that that was the way to go.

I think using "+" for string concatenation not ideal, since "+" normally
denotes a commutative operation (modulo overflow, in the case of finite
precision numbers), whereas string concatenation is not commutative.
In addition, overloading "+" on strings might be make things a bit too
ambiguous, making the code harder to read and (when using type inference)
requiring more explicit type declarations.

So I think infix "++", a la Haskell, would be a better choice.

This one is pretty easy to implement, so if you're keen, please
implement it and send us the patch.

(Getting the compiler to perform concatenation of string literals at
compile time is a little more work, but that wouldn't be necessary for
a first cut.  If you do want to have a go at that then it I think adding
a single clause for evaluate_builtin in compiler/const_prop.m should suffice.)

Cheers,
	Fergus.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list