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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id EA2D1BBC4 for ; Wed, 4 Mar 2009 15:20:05 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsBABsdrklKfVwYjmdsb2JhbACUQj8BAQEBCQsICQ8FsSQHgQCQLQEDAQOEBQaCfYFB X-IronPort-AV: E=Sophos;i="4.38,301,1233529200"; d="scan'208";a="36082926" Received: from qw-out-2122.google.com ([74.125.92.24]) by mail4-smtp-sop.national.inria.fr with ESMTP; 04 Mar 2009 15:20:05 +0100 Received: by qw-out-2122.google.com with SMTP id 3so2475732qwe.15 for ; Wed, 04 Mar 2009 06:20:04 -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=X+MRARP04NUlvuZ6pOeYdr20415nPHNMpNvFcWsMeko=; b=C0Fz0yVaU4xEVH9qAWcdoN4eF+HsBe3MxaHpDw/vclYC9qz5fP2nDepnG0L9+6d6Xt DC9s7ZEO8LmHCwQUVqqMoQ+0m0YkBpcFuNHGY5Hnt0XvlB625U1tXG6Fgmvv6hROd+P8 XxwpNg48jHWJ8fqyICAR0ADgBc5ikJj3OgvDA= 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=c8xNiqRmfK8JEEgoVhyTel/bPnoYu+Wj9nGAK6Ezv6RPIvQf1oIlkDAhNQVsZiteS0 z6smxMtbIA+9F79f5a4uHm/67+OhRiVE8V0Kch1HF0Jzwr++CuL/apCq/yLmp1akGK8e 4fix9u4/F2BWAbVGq33/uV2PdedThX3L4sUu4= Received: by 10.224.73.131 with SMTP id q3mr11721648qaj.44.1236176404004; Wed, 04 Mar 2009 06:20:04 -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 9sm5473094ywf.26.2009.03.04.06.20.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 04 Mar 2009 06:20:03 -0800 (PST) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? Date: Wed, 4 Mar 2009 09:19:58 -0500 User-Agent: KMail/1.9.9 Cc: Brian Hurt , Jon Harrop References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <200903040159.48574.jon@ffconsultancy.com> In-Reply-To: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903040920.01990.peng.zang@gmail.com> X-Spam: no; 0.00; stl:01 hash:01 functors:01 functors:01 functorize:01 functorizing:01 peng:98 peng:98 2009:98 pope:98 wrote:01 rec:01 naming:01 caml-list:01 div:97 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 04 March 2009 01:11:18 am Brian Hurt wrote: > This is another large factor. The three reasons functors aren't used very > much are because: > 1) They're a big, scary name, > 2) They're slightly less efficient, > 3) There are no good tutorials about how to use them, and > 4) A fanatical devotion to the pope. > > I'll come in again... Ha! =] But I'll add one more reason. With functors you have extra overhead like having to be explicit with what function you're using. In your example when you want to use Newton's method you always must write "RatioNewton.newtons" or "FloatNewtons.newtons". The alternative is to functorize the call site, but (1) that has its own cost: lots of boilerplate functorizing code crowding the real code and (2) you just defer the explicit naming cost as when that function is called you'll still have to call either Float version or Ratio version. I think objects are much closer to type classes and a much nicer solution. You can write: class type ['a] num : object method add : 'a -> 'a -> 'a method mul : 'a -> 'a -> 'a method sub : 'a -> 'a -> 'a method div : 'a -> 'a -> 'a method abs : 'a -> 'a -> 'a end let rec newtons : ('a #num as 'b) -> ('b -> 'b) -> ('b -> 'b) -> 'b -> 'b = ... Peng -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFJro4RfIRcEFL/JewRAr0MAJ47aFyEvb4yzHOFVqVH/mS8w0TOfgCePNSE HhVmyyi56RQ8y4gVpICcfXE= =rz4T -----END PGP SIGNATURE-----