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=1.5 required=5.0 tests=AWL,DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id E021EBBC4 for ; Wed, 4 Mar 2009 21:11:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj8BAKxurkmArgVglGdsb2JhbACVAwEBAQEJCwgJEQTDAQeEAQY X-IronPort-AV: E=Sophos;i="4.38,302,1233529200"; d="scan'208";a="25074246" Received: from expredir5.cites.uiuc.edu ([128.174.5.96]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Mar 2009 21:11:32 +0100 Received: from axyr (aryx.cs.uiuc.edu [128.174.236.106]) by expredir5.cites.uiuc.edu (8.14.2/8.14.2) with ESMTP id n24KBNim027547; Wed, 4 Mar 2009 14:11:24 -0600 (CST) To: Brian Hurt Cc: Yoann Padioleau , Jon Harrop , caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <200903032342.39527.jon@ffconsultancy.com> <87r61eyu5c.fsf@aryx.cs.uiuc.edu> From: Yoann Padioleau Date: Wed, 04 Mar 2009 14:11:11 -0600 In-Reply-To: (Brian Hurt's message of "Tue\, 3 Mar 2009 23\:56\:26 -0500 \(EST\)") Message-ID: <87ab81yrog.fsf@aryx.cs.uiuc.edu> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 functor:01 foo:01 struct:01 struct:01 recompile:01 Brian Hurt writes: >>>> 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. my point is I don't want to functorize it; I want to solve a problem, and I am looking for the fastest way to get there. If you start with the assumption that you want to functorize something, then indeed you will need a functor ... > 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). My goal is not being backward compatible. Of course you can keep your old function and define new functions ... My goal is to evolve code, so I want to change the behavior of 'foo', and I want to benefit from this new behavior, but I want this evolution to have the less collateral effects on the structure of the rest of the program. For instance I got a set of functions that were working on some 'a stuff, and I was using somewhere a naive list as a first draft. Later I want to optimize things, and put those 'a in a more efficient data-structure, but if use the Map data-structure, then I will be forced to change lots of things. Argh, damned. Well, wait, I will just use the defunctorized interface of Hashbtl :) Again, just imagine one second that 'a list were not present in OCaml, and that the only way you had to make a list would be to use a functorized interface of a List module. Would you like that ? (that's what we are forced to do when using Map and that's why I always use Hashtbl instead). > > 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