archives

Overloading in a dynamic functional language

Hi,
it looks like I have a little problem with overloading in my own programming language Ela. (There is a prototype here if you are interested: http://groups.google.com/group/elalang/browse_thread/thread/ee93a6de62533b22)

What we have:
* a functional language (not a pure one but pretty oriented towards pure functional programming)
* a dynamic language

Without overloading it is even not possible to implement your own numeric type and support standard operators for it such as "+", "-", etc. So it seems like a very handy thing to have. However when we take a dynamic functional language it is not really clear what is the direct way to go.

The requirement is - to have overloaded functions as first class functions (first class values).

I have one solution but it looks like I actually created solid ground for side effects. This is how it works:

open Con

let foo x = "foo1"
 on Any

let _ = writen (foo 12)

let foo x = "foo2"
 on Int#
 
let _ = writen (foo 12)

The first function is overloaded for "any" type, the second - only for integers. Overloads are dynamic and are processed as regular bindings (in the order of execution). And here is the result - when I call "foo" function before the second overload a first implementation is called, but after the second overload the second implementation fits best and it gets called. The function invocation code is the same in both cases as you see.

I have a strong feeling that this is a problem. What do you think?
Also what are other ways to do "pure" overloading? If I want to preserve regular bindings semantics.

Thanks.