Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Why are arithmetic functions not polymorph?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: brogoff@s...
Subject: Re: [Caml-list] Why are arithmetic functions not polymorph?
On Fri, 23 May 2003, Brian Hurt wrote:
> On Fri, 23 May 2003 brogoff@speakeasy.net wrote:
> OK.  I'm reading the readme.  First off, congratulations, you're dodging a 
> lot of the bullets that C++ didn't.  
> 
> Here's a question.  Consider the following code:
> 
> generic one = | int => 1 | float => 1.0
> 
> generic two = | int => 2 | float => 2.0
> 
> generic plus = | int -> int -> int = (+)
>                | float -> float -> float = (+.)
> 
> plus one two;;
> 
> What's the result?  Is it the int 3, or the float 3.0?

Syntax error ;-)

Fixing that, the int 3. Like pattern matching, if the first matches, 
that wins. If you reorder, you can make it return float. 

> Another problem already arises with the generic (aka overloaded)  
> comparisons- you oftentimes need to arbitrarily specify types in order to
> replace the expensive call to the generic compare with a much cheaper
> inlined type-specific compare.  If you start having to specify types a lot 
> more often, that reduces the advantage of having type inference.

I don't see that as too much of  a problem, but maybe with more experience 
my opinion will change. 

> > New operators are not sufficient, and SML is more powerful in it's ability to 
> > define new operators than OCaml (minus CamlP4) is. 
> 
> Yeah- I'd like to be able to define accessor operators somehow.  Say being
> able to define $[ ] as hashtbl lookups, so that h$[3] ==> Hashtbl.find h
> 3.

Pierre Weis alluded to this desire in an ealier discussion of generics.

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners