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.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 1E712BBC4 for ; Wed, 4 Mar 2009 05:57:02 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApECAK+YrUnYi40JmWdsb2JhbACBTpM5AQEBAQEICwoHEcEahAgG X-IronPort-AV: E=Sophos;i="4.38,298,1233529200"; d="scan'208";a="36055531" Received: from mail-out9.nyct.net (HELO mail.nyct.net) ([216.139.141.9]) by mail4-smtp-sop.national.inria.fr with ESMTP; 04 Mar 2009 05:57:01 +0100 Received: from beast.local (pool-96-250-132-59.nycmny.east.verizon.net [96.250.132.59]) (authenticated bits=0) by mail.nyct.net (8.14.2/8.14.1) with ESMTP id n244ur5q096389 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Tue, 3 Mar 2009 23:56:54 -0500 (EST) (envelope-from bhurt@spnz.org) Date: Tue, 3 Mar 2009 23:56:26 -0500 (EST) From: Brian Hurt X-X-Sender: bhurt@beast To: Yoann Padioleau Cc: Jon Harrop , caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? In-Reply-To: <87r61eyu5c.fsf@aryx.cs.uiuc.edu> Message-ID: References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <200903032342.39527.jon@ffconsultancy.com> <87r61eyu5c.fsf@aryx.cs.uiuc.edu> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam: no; 0.00; stl:01 functors:01 ocaml:01 functors:01 ocaml:01 functor:01 entail:01 foo:01 functorize:01 functorize:01 foo:01 struct:01 struct:01 functor:01 recompile:01 On Tue, 3 Mar 2009, Yoann Padioleau wrote: > Brian Hurt writes: > >> On Tue, 3 Mar 2009, Jon Harrop wrote: >> >>> Functors give >>> you the same capability in OCaml but they are rarely used precisely because >>> the functionality is not very useful. >> >> I think I disagree with this. I think functors aren't used very much >> in Ocaml because: > > 0) they are intrusive! putting code inside a functor may entail the > need to modify also lots of related code. That's one of the worst > thing for a programming feature. Your modification can not be local. I > hate monad for the same reason, and I like ocaml exception mechanism, > and using sometimes global refs for the same reason. No. Here's what you can do. Say you had an old function: let foo x = ... and you want to functorize it for whatever reason. But you have lots of code depending upon the old type signature that you don't want to change. First, you functorize foo: module Make(X: Whatever) = struct let foo x = ... end;; Then you include the "classic foo", like: module T = Make(struct ... old defns ... end);; include T;; Where ... old defns ... is all the original types and functions that foo used that are now provided by the functor. So you now have a module that exports both a "functorized" foo and a "classic" foo, and all the old code continues to just work (after a recompile, natch). This is much the same trick you use in Haskell when adding a typeclass dependency to the signature of a function- so long as you provide a typeclass instance for the old type, the old code continues to work with a recompile. I also comment, this is also a problem C++ templates have- templatizing a class in C++ is also an "intrusive" change. Brian