Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] F#
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] F#
On Thu, 2007-03-08 at 12:54 -0500, Brian Hurt wrote:
> Roland Zumkeller wrote:
> 
> > Wasn't there a more or less good reason for OCaml *not* to support
> > operator overloading?
> >
> Yes.  Ocaml has modules and functors.  IMHO, any time you thing "boy, 
> it'd be really nice to use operator overloading here", you should use a 
> module and a functor instead.

Unfortunately you often cant do that easily:

* functors don't scale to separate compilation

* separate compilation doesn't support inter-unit recursion

* functors have a huge book-keeping overhead
(I mean syntactic overhead, not performance overhead)

* functors are hard to combine

The first two issues are implementation problems rather than
intrinsic to the language in the abstract.

The book-keeping problem is a consequence of the fine grained
control functors provide, compared with say Haskell typeclasses.

The combination problem is best characterized by an expert.

A lot of the time you want a data functor, not a module
functor, and higher order data functors (functorial
polymorphism) aren't available in Ocaml.

For example if you have some container you just want
to fold over it, which means you want a polyadic fold.
Module functors help *define* a fold which is polymorphic
over signature arguments, but don't provide polyadic usage.

Although the mechanism used in C++ is unsound, C++ 
does provide polyadic programming, and in that sense
is way ahead of Ocaml and Haskell. Despite the unsoundness,
generics in C++ usually 'just work anyhow'.

However .. and Harrop "interactive" crowd note .. functors
do provide one advantage. Because of the mandatory
book-keeping they're amenable to use of a Form based GUI/IDE
to assist in definition:

	Functor Hashtbl
	key		| <instantiating type here>
	compare         | < defn here>
	hash            | <defn here>


[That's supposed to be a form where the signature is listed in
a column format, and the programmer just fills in the
definitions]

I would probably hate that BUT it would sure help noobs learn
to use first order functors.

In fact you could use a little cheat .. and call them 
static classes, and tell people it's an Ocaml kind of OO .. 
(Haskell does this little cheat .. it makes typeclasses
very easy to explain to OO people).


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net