From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p89NEgxA003293 for ; Sat, 10 Sep 2011 01:14:47 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah8CAFKdak7RVaE2kGdsb2JhbABCmUOOTQgUAQEBAQkJDQcUBCKBawITGQEbHgMSCQEGXQERAQUBV593glUKiz6CV4VNO4htAgMGhmgEh22LS4xyPYQK X-IronPort-AV: E=Sophos;i="4.68,358,1312149600"; d="scan'208";a="108354894" Received: from mail-fx0-f54.google.com ([209.85.161.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 10 Sep 2011 01:14:47 +0200 Received: by fxe4 with SMTP id 4so5590478fxe.27 for ; Fri, 09 Sep 2011 16:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=6Grh9cED/iRCzIzksLT8xDEMDfKEnoDjxS/esKbI/Pk=; b=h0xu9kGBYEkWuAhw3tOFtWcsUmwDiBxDpk3ce8y8bz+R6q3nefJYN4HrkE9yALqVb4 anQKWx9LB6mOcr1e6QHtCJMkjUxOwGcITgqat01uzn/Fqir070/lmbjqlzKIRnUw72LL 25noHHpKCIJQD7a345i+ume3GswJ2yQJm8uLI= MIME-Version: 1.0 Received: by 10.223.21.141 with SMTP id j13mr178739fab.79.1315610086784; Fri, 09 Sep 2011 16:14:46 -0700 (PDT) Received: by 10.223.109.195 with HTTP; Fri, 9 Sep 2011 16:14:46 -0700 (PDT) Date: Fri, 9 Sep 2011 17:14:46 -0600 Message-ID: From: Anthony Tavener To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=00151740271ae2be5704ac8a57fd Subject: [Caml-list] Mutually recursive closures? --00151740271ae2be5704ac8a57fd Content-Type: text/plain; charset=ISO-8859-1 I was considering returning a couple of closures to help organize my UI code, essentially representing current UI mode by one of these closures. But then I run into a problem because the types are infinite (returns a function, which returns a function, ...) A simplified example: # let rec a () = printf "state a\n"; b and b () = printf "state b\n"; a Error: This expression has type unit -> unit -> 'a but an expression was expected of type 'a Is there a way I can do this? To express (or 'hide') the cyclic nature of the type resolution? I've considered using continuations, but that seems heavy-weight for what I'm looking to do. And as far as I can tell I'd need to leverage Oleg's delimcc (which I'd love to start using and wrap my head around -- but for a task worthy of it!). I can use a variant to represent states/modes and have a dispatcher which runs the right code... but this introduces what feels like an unnecessary layer of distraction. Returning the closure of the "next state" seems straightforward, but introduces cycles into the typing. :( I'm hoping I'm missing something simple. Thank-you for any assistance! -Tony --00151740271ae2be5704ac8a57fd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I was considering returning a couple of closures to help organize my UI cod= e, essentially representing current UI mode by one of these closures. But t= hen I run into a problem because the types are infinite (returns a function= , which returns a function, ...)

A simplified example:

# let re= c a () =3D printf "state a\n"; b
=A0 =A0 =A0 =A0and b (= ) =3D printf "state b\n"; a

E= rror: This expression has type unit -> unit -> 'a
=A0 =A0 =A0 =A0but an expression was expected of type 'a


Is there a way I can do this? To expre= ss (or 'hide') the cyclic nature of the type resolution?
=
I've considered using continuations, but that seems heavy-we= ight for what I'm looking to do. And as far as I can tell I'd need = to leverage Oleg's delimcc (which I'd love to start using and wrap = my head around -- but for a task worthy of it!).

I can use a variant to represent states/modes and have = a dispatcher which runs the right code... but this introduces what feels li= ke an unnecessary layer of distraction. Returning the closure of the "= next state" seems straightforward, but introduces cycles into the typi= ng. :(

I'm hoping I'm missing something simple. Thank-= you for any assistance!

=A0-Tony

--00151740271ae2be5704ac8a57fd--