From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id C0F0ABC6C for ; Fri, 9 Mar 2007 00:07:12 +0100 (CET) Received: from ipmail03.adl2.internode.on.net (ipmail03.adl2.internode.on.net [203.16.214.135]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l28N79jx001942 for ; Fri, 9 Mar 2007 00:07:11 +0100 Received: from ppp19-103.lns2.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.19.103]) by ipmail03.adl2.internode.on.net with ESMTP; 09 Mar 2007 09:37:07 +1030 X-IronPort-AV: i="4.14,264,1170595800"; d="scan'208"; a="60037090:sNHT22423387" Subject: Re: [Caml-list] F# From: skaller To: Brian Hurt Cc: Roland Zumkeller , caml-list@yquem.inria.fr In-Reply-To: <45F04DD0.5010505@janestcapital.com> References: <3D1E4D9CA9BCE04D8F2B55F203AE4CE30666AB5E@selma.roomandboard.com> <200703081510.56667.jon@ffconsultancy.com> <45F04DD0.5010505@janestcapital.com> Content-Type: text/plain Date: Fri, 09 Mar 2007 10:07:02 +1100 Message-Id: <1173395222.6613.22.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45F0971D.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 overloading:01 ocaml:01 functors:01 overloading:01 functor:01 functors:01 compilation:01 compilation:01 recursion:01 haskell:01 functor:01 polymorphism:01 haskell:01 hashtbl:01 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 | compare | < defn here> hash | [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 Felix, successor to C++: http://felix.sf.net