Hacker News new | ask | show | jobs
by dean177 2486 days ago
This isn’t really true.

You can do: let ( + ) a b = ...

Just fine

1 comments

That's a custom operator definition. Operator overloading is when the same operator can be used on different types (for example, if `+` worked on both floats and ints, instead of explicitly having to reach for the correct `+` like you do in OCaml).
Which can be done, since OCaml has objects

    let (+) a b = a#add b
Yeah, I guess you can get a limited sort of operator overloading by building it out of row polymorphism. That doesn't solve the most common use-case of operator overloading, though, which is allowing the same operators to work on floats and ints, because it only works on objects.