Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Understanding why Ocaml doesn't support operator overloading.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mike Lin <mikelin@M...>
Subject: Re: [Caml-list] Understanding why Ocaml doesn't support operator overloading.
> The problem is what *assembly code* should be generated for function f?
> Code to add 2 integers or code to add 2 floats? Hmm.. we'll have a
> problem then. Or maybe both? And choose versions of f based on type it
> is applied to? But then consider:
> let f x1 x2 ... xn = ((x1 + x1), (x2 + x2), ..., (xn + xn))
> you need to generate 2^n versions of f. We're getting to ugly things
> like C++ templates here.

If this is really a problem then what gets generated when you write any 
polymorphic function at all? The proposal is to allow constrained 
polymorphism; the polymorphism that is already in OCaml seems to 
supersede this with regard to the above objection.

I wonder if the unification algorithm can be generalized to intersect 
sets of allowable types instead of unifying "for all" type variables. 
It doesn't seem too ludicrous in principle but I could easily have 
missed some nasty corner case.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: