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.2 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 914BFBC54 for ; Thu, 5 Mar 2009 00:14:28 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiIHAESarknUnwdkZGdsb2JhbACCHZJOGgkFBwcPBsMihAgG X-IronPort-AV: E=Sophos;i="4.38,304,1233529200"; d="scan'208";a="22064823" Received: from relay.pcl-ipout02.plus.net ([212.159.7.100]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Mar 2009 00:14:28 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An4FAMuZrknUnw4R/2dsb2JhbACCHdY5hAgG Received: from pih-relay04.plus.net ([212.159.14.17]) by relay.pcl-ipout02.plus.net with ESMTP; 04 Mar 2009 23:14:28 +0000 Received: from [87.112.234.120] (helo=leper.local) by pih-relay04.plus.net with esmtp (Exim) id 1Lf0IF-0004fb-Ta for caml-list@yquem.inria.fr; Wed, 04 Mar 2009 23:14:28 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? Date: Wed, 4 Mar 2009 23:19:51 +0000 User-Agent: KMail/1.9.9 References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <871vtczz94.fsf@aryx.cs.uiuc.edu> In-Reply-To: <871vtczz94.fsf@aryx.cs.uiuc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903042319.51632.jon@ffconsultancy.com> X-Plusnet-Relay: f5631aaaecca689962fed60bb80d083b X-Spam: no; 0.00; stl:01 ocaml:01 hashtbl:01 functors:01 functors:01 parametrize:01 ord:01 overkill:01 pervasives:01 run-time:01 functor:01 haskell:01 haskell:01 inference:01 ocaml:01 On Wednesday 04 March 2009 22:42:15 Yoann Padioleau wrote: > Brian Hurt writes: > > On Wed, 4 Mar 2009, Yoann Padioleau wrote: > >> 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). > > > > Humorously enough, I'm doing exactly this. In a bunch of code I'm > > playing with, I've implemented an NeList module- nothing fancy, just a > > few dozen lines of code and the basic list operations, only the lists > > can not be empty. They always have to contain at least one element. > > > > But seriously, you hate functors that much? > > With a passion :) I don't like functors for generic data structures > such as Map. > > If you have some code that you want to parametrize over multiple types, > and each of this type has some complex constraints, then I like functors. Exactly. > But when the only constraints on your type is that you want a Ord, or a Eq > (or a Show), then I think functors are overkill, Yes. > and I am fine with the default Pervasives.compare No, that is really error prone. You want "compare" to run-time dispatch to the appropriate comparison function (e.g. Set.compare) when it hits a reference type. > In a similar way, you have some complex code polymorphic in a 'a > and at some point, deep inside a call chain, you want to print > some debugging information about this tiny 'a, so you really > want to do a generic_print x, but you can not. > Or if you want to do that you have to turn that into a functor > taking a T where the T is contrained to have a 'print' method/function. > With haskell you just write 'show x', and haskell inference will > do the work to add the Show a =>. So right now in OCaml > I tend to use the Dumper module of Richard Jones. When I can > avoid functors, I do so. Right. Generic printing in HLVM is nice. :-) -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e