Overloading (was Re: Algorithmic lists )

Robert Virding rv@REDACTED
Tue Oct 17 12:11:33 CEST 2000


Andy with Recycled Electrons <aba3600@REDACTED> writes:
>
>Also, is there a way to overload operators (not function calls) in Erlang?
>I'd love to overload "+" or "-" for a specific kind of input, so that a
>call is made to my function.  The data units I am passing in are 3-element
>tuples right now, but I can change that.
>
>I.E., In the second half of this eMail I am searching for a way to define
>my own data type in Erlang and overload existing operators based on it.
>Does anyone have an example?

No, we didn't really think it is such a good idea.  It is VERY NICE to
be able to look at an operator and KNOW what the argument and result
types must be.

Anyway with a dynamically typed language it is not so easy as you have
to redefine the functions/built-ins/primitives the operators end up
calling.  You can't fix that at compile time.

You could perhaps do it with parse transforms, but again without proper 
type information it is not easy.

The "proper" way to define a set of functions operating on the types.

	Robert

-- 
Robert Virding                          Tel: +46 (0)8 545 55 017
Alteon Web Systems                      Email: rv@REDACTED
S:t Eriksgatan 44                       WWW: http://www.bluetail.com/~rv
SE-112 34 Stockholm, SWEDEN
"Folk säger att jag inte bryr mig om någonting, men det skiter jag i".





More information about the erlang-questions mailing list