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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 40DC6BBB8 for ; Tue, 9 Sep 2008 16:11:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkkCAFwgxkjAXQImiGdsb2JhbACSTgEBAQ8gnE2GUYFk X-IronPort-AV: E=Sophos;i="4.32,365,1217800800"; d="scan'208";a="28980079" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Sep 2008 16:11:14 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m89EBDv6020835 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 9 Sep 2008 16:11:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuwBAOQgxkhQW+UCgWdsb2JhbACSTgEBECAEnEqGUoFk X-IronPort-AV: E=Sophos;i="4.32,365,1217800800"; d="scan'208";a="16747061" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 09 Sep 2008 16:11:13 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kd3vz-0006Zf-Dt for caml-list@inria.fr; Tue, 09 Sep 2008 14:11:11 +0000 Received: from ivr94-8-88-162-26-239.fbx.proxad.net ([88.162.26.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2008 14:11:11 +0000 Received: from zheng_li by ivr94-8-88-162-26-239.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2008 14:11:11 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Zheng Li Subject: Re: killing a cat Date: Tue, 09 Sep 2008 16:11:17 +0200 Message-ID: <48C68405.2020900@users.sourceforge.net> References: <0233247D-28D8-4C83-9EFB-6FD4B50B3D8B@metaweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org Cc: warren@metaweb.com X-Gmane-NNTP-Posting-Host: ivr94-8-88-162-26-239.fbx.proxad.net User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) In-Reply-To: <0233247D-28D8-4C83-9EFB-6FD4B50B3D8B@metaweb.com> Sender: news X-Miltered: at discorde with ID 48C68401.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; qualifiers:01 warren:98 sourceforge:01 wrote:01 int:01 int:01 data:02 define:02 structures:02 parameter:02 restrict:02 string:02 string:02 seems:03 handler:03 Hi, Warren Harris wrote: > Now, I could get around this by making "f" be a function that when > evaluated returns the result of the helper. However, I'm trying to > avoid that because in the real implementation, the work of the helper > is somewhat expensive and should only be performed once. An > alternate solution can be achieved by pushing the universal qualifier > for the result type down into the handler: > > type 'a handler = { handle : 'b . 'a -> (string -> 'a -> 'b, 'b) > writer } I think it's reasonable to use universal qualifier here. > I am forced into reworking the helper parameter function, wf, to also > become a record in order for it to be universally qualified: > > type 'a field_handler = { write_field : 'b . string -> 'a -> (unit -> > string -> 'a -> 'b) -> 'b } > > This works: > > let helper name wf = { handle = fun a k -> wf.write_field name a k } > let f = helper "f" write_int_field It's hard to tell where a better option is without knowing your overall design on types and data structures. On the other hand, I would usually restrict universal qualifiers into a range as small as possible. In your example, I would probably define as the follows: type 'a handler = { handle: 'a -> (string * 'a) writer } and 'a writer = { write: 'b. (unit -> 'a -> 'b) -> 'b } let helper name wf = { handle = wf name } let write_int_field s i = { write = fun k -> k () (s, i+1) } let f = helper "f" write_int_field which seems simpler to me. However this really depends on your overall design. HTH. -- Zheng