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=2.8 required=5.0 tests=DNS_FROM_RFC_POST,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 82181BBD5 for ; Wed, 4 Mar 2009 01:14:00 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmECAJdWrUlKfSweimdsb2JhbACUST8BAQEKCQwHDwWwaAeBAI99AQMBA4QFBoJ4gUI X-IronPort-AV: E=Sophos;i="4.38,297,1233529200"; d="scan'208";a="23818320" Received: from yx-out-2324.google.com ([74.125.44.30]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Mar 2009 01:13:59 +0100 Received: by yx-out-2324.google.com with SMTP id 31so1823496yxl.3 for ; Tue, 03 Mar 2009 16:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:content-type :content-transfer-encoding:content-disposition:message-id; bh=FR9EnqxQ63pF+ZWd81N6vQrQm2VktH8+i9Zuf/vaU7Y=; b=hm4q0gdbWAQkthZItFtgtZqHmRwWvM9KwE37/A5EaLodZsn5e60DLeCIHb1uOr4DoF Ja5x9dN2B9UNoKbZf8MHb8OBUhitM3F0HQ8XOy9IjHTXW0BkUU9xOas+vk9ad+iF4Ws1 U+K6zMdNWwwcjb2WU9EcD9Wg6LnqGAE5MYWP8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :content-type:content-transfer-encoding:content-disposition :message-id; b=VhVbto9/E+PIL23lEanbPqH3M9bsv+9fYe9O4bDmDc3Dy1pPdfLq/PDal/F+ISkUEj 2NbCSq1RaoR9Fd8IzVYBN3CnC0hsUAgySyXMhtP1BBRDKJ+SVqy/uv+QWWrOZARqDWfg TctlHHw8+cPI+FlmFwm/JwanRIXhDZSZ3vK0g= Received: by 10.100.137.12 with SMTP id k12mr6231243and.55.1236125638937; Tue, 03 Mar 2009 16:13:58 -0800 (PST) Received: from ?192.168.0.102? (c-98-219-43-7.hsd1.ga.comcast.net [98.219.43.7]) by mx.google.com with ESMTPS id d38sm9769688and.49.2009.03.03.16.13.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 03 Mar 2009 16:13:58 -0800 (PST) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? Date: Tue, 3 Mar 2009 19:13:53 -0500 User-Agent: KMail/1.9.9 Cc: Jon Harrop References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <87zlg2z19g.fsf@aryx.cs.uiuc.edu> <200903032336.53089.jon@ffconsultancy.com> In-Reply-To: <200903032336.53089.jon@ffconsultancy.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903031913.57035.peng.zang@gmail.com> X-Spam: no; 0.00; stl:01 hash:01 stl:01 arrays:01 hash:01 iterator:01 ocaml:01 ocaml:01 functor:01 functors:01 statically:01 functors:01 peng:98 peng:98 2009:98 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 03 March 2009 06:36:52 pm Jon Harrop wrote: > On Tuesday 03 March 2009 22:31:55 Yoann Padioleau wrote: > > Also, a maybe good thing with STL is that you can write a single 'find' > > or 'sort' function that will work for every kind of collections > > (list, arrays, map, hash, etc) by using the > > indirect iterator idiom, without the penalty of dynamic dispatch > > solutions. I am not sure OCaml can do that too. > > OCaml can do that too. Just wrap your code in a functor and parameterize it > over the module implementing the data structure (e.g. List or Array). > Modules and functors are second-class statically resolved constructs in > OCaml so there is no dynamic dispatch. As usual I want to point out the alternative: objects. Eg. you can write a function that takes any object with the "find" method and look for . Objects in contrast to functors are dynamically dispatched so they are more flexible but just a little slower (method calls are cached). It also lets you make calls to find without being explict. Eg. instead of List.find or Array.find or Set.Make(String).find, you can just do #find. Peng -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFJrcfEfIRcEFL/JewRAsEzAKCfu/LbvuvPVDCCsOI8Kmi8cfHtTwCfZfEX ffjw1sTrYzJHbr0d8QQuaQw= =yXcr -----END PGP SIGNATURE-----