From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id A057CBC37 for ; Sun, 25 Oct 2009 16:04:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEADYG5EpeFxRU/2dsb2JhbACEcb9aj2uBMoI6UwQ X-IronPort-AV: E=Sophos;i="4.44,621,1249250400"; d="scan'208";a="38923668" Received: from glyptal.glondu.net ([94.23.20.84]) by mail1-smtp-roc.national.inria.fr with ESMTP; 25 Oct 2009 16:04:02 +0100 Received: from [10.198.42.2] (unknown [10.198.42.2]) by glyptal.glondu.net (Postfix) with ESMTP id A871B59DEA; Sun, 25 Oct 2009 16:03:59 +0100 (CET) Message-ID: <4AE468DF.806@glondu.net> Date: Sun, 25 Oct 2009 16:03:59 +0100 From: =?UTF-8?B?U3TDqXBoYW5lIEdsb25kdQ==?= User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090701) MIME-Version: 1.0 To: Mathias Kende Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] forbidden construct as right hand side of "let rec" References: <1256250121.4178.37.camel@MATHIAS-ENS> <4AE0DDF5.8040601@glondu.net> In-Reply-To: X-Enigmail-Version: 0.95.0 OpenPGP: id=49881AD3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; intuitively:01 cheers:01 phane:98 steph:98 mathias:98 phane:98 rec:01 rec:01 assert:01 caml-list:01 construct:02 let:03 let:03 tmp:05 tmp:05 Mathias Kende a =C3=A9crit : > [...] I also want to write : > let rec h =3D t (f h) > (with t : ('a -> 'b) -> 'a -> 'b) but here, I can't afford to use > let rec h x =3D t (f h) x > because t as some side effects and I need it to be evaluated only once.= Then what about: let h =3D let tmp =3D ref (fun x -> assert false) in let res x =3D !tmp x in tmp :=3D (fun x -> let y =3D t (f res) in tmp :=3D y; y x); res Intuitively, the "tmp" reference caches the call to "t (f h)", but this is otherwise the same technique as I gave earlier. Cheers, --=20 St=C3=A9phane