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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id BC5ABBBC4 for ; Wed, 4 Mar 2009 23:42:38 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak0BAEuSrkmArgW7kWdsb2JhbACUeAEBAQEJCwoHEQTDJgeEAQY X-IronPort-AV: E=Sophos;i="4.38,303,1233529200"; d="scan'208";a="36107668" Received: from expredir4.cites.uiuc.edu ([128.174.5.187]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Mar 2009 23:42:38 +0100 Received: from axyr (aryx.cs.uiuc.edu [128.174.236.106]) by expredir4.cites.uiuc.edu (8.14.2/8.14.2) with ESMTP id n24MgS1Z002871; Wed, 4 Mar 2009 16:42:28 -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> <87ab81yrog.fsf@aryx.cs.uiuc.edu> From: Yoann Padioleau Date: Wed, 04 Mar 2009 16:42:15 -0600 In-Reply-To: (Brian Hurt's message of "Wed\, 4 Mar 2009 16\:59\:51 -0500 \(EST\)") Message-ID: <871vtczz94.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 ocaml:01 hashtbl:01 functors:01 functors:01 parametrize:01 ord:01 overkill:01 pervasives:01 functor:01 typeclass:01 inference:01 haskell:01 ord:01 functor:01 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. 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, and I am fine with the default Pervasives.compare Also I tend to find harder to understand code using functors ... You can get many signatures, functors taking functors, ... I am not evolved enough to handle that. > The overhead of doing: > > module StringMap = Map.Make(String);; > > is so high to you, that you simply don't do it? I do that sometimes, and I also have a IntMap and IntIntMap. The problem is when your code has some 'a involved, and that your key is for instance a pair, or triple of stuff having a polymorphic type. Then, before, I had a function taking some 'a and returning some 'b, and internally it was using a list and everything was fine. Then one day I want to optimize this and use internally a Map and then everything goes down ... I have to change the signature of my function taking a 'a into a functor now taking a T, and also do that for its caller, etc, etc. With typeclass, most of this tedious boilerplate work would be done behind the scene for me thanks to type inference. Haskell will just propagate the need to have a Ord a => in addition to the original signature of 'a -> ... 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. > > Mind if I ask why? > > Brian