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 p8A0l770005544 for ; Sat, 10 Sep 2011 02:47:07 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmYBAHSyak7RVaE2kGdsb2JhbABCpxl3CBQBAQEBCQkNBxQEIoFSAQEBAQIBEgITGQEbHQEDAQsGBQQHDS4hAQERAQUBHAYTIodUmlYKiz6CV4VBO4htAgMGhmgEh22LTYoGgmw9hAs X-IronPort-AV: E=Sophos;i="4.68,359,1312149600"; d="scan'208";a="108362684" 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 02:47:02 +0200 Received: by fxe4 with SMTP id 4so5664282fxe.27 for ; Fri, 09 Sep 2011 17:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3xu+YUuSgX4itHv9FynqmI/ovTe4gBouIlt38JVGoZw=; b=CgF2oAg+SHFn6qzkT9gGb2+BROprCU9BpFU91LSEp/Nj66rPkZ9xMXhyvmdBEhz/IZ CmWTPxwPzob1hoCK7DEas4DML/BdqS5s4US54CJPcLPjTH9WeyMJI4VQo561rU7+LERu yWW5+iMF4fleoRnukCajoE85YIqRBX+HH86Eg= MIME-Version: 1.0 Received: by 10.223.21.141 with SMTP id j13mr299895fab.79.1315615621563; Fri, 09 Sep 2011 17:47:01 -0700 (PDT) Received: by 10.223.109.195 with HTTP; Fri, 9 Sep 2011 17:47:01 -0700 (PDT) In-Reply-To: <4E6AA1E1.9050307@gmail.com> References: <4E6AA1E1.9050307@gmail.com> Date: Fri, 9 Sep 2011 18:47:01 -0600 Message-ID: From: Anthony Tavener To: Jonathan Protzenko Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=00151740271ac8c68804ac8ba160 Subject: Re: [Caml-list] Mutually recursive closures? --00151740271ac8c68804ac8ba160 Content-Type: text/plain; charset=ISO-8859-1 Thanks Jonathan! I've seen -rectypes mentioned over the years and always glossed over it thinking "Ah, I'll never need that!" :P Understandable that it's a good default to have disabled. I'll experiment first and if I like the results I'll try to limit compiling with -rectypes to the smallest bit of code using it. On Fri, Sep 9, 2011 at 5:31 PM, Jonathan Protzenko < jonathan.protzenko@gmail.com> wrote: > You can use equirecursive types, which can be enabled through the -rectypes > command-line switch. With that option, your example above type-checks. > However, these are not enabled by default for a variety of reasons, the most > important one being it makes it much easier to shoot yourself in the foot. > > Cheers, > > jonathan > > > On Sat 10 Sep 2011 01:14:46 AM CEST, Anthony Tavener wrote: > >> 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 >> >> --00151740271ac8c68804ac8ba160 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks Jonathan! I've seen -rectypes mentioned over the years and alway= s glossed over it thinking "Ah, I'll never need that!" :P
Understandable that it's a good default to have disable= d. I'll experiment first and if I like the results I'll try to limi= t compiling with -rectypes to the smallest bit of code using it.


On Fri, Sep 9, 2011 at 5= :31 PM, Jonathan Protzenko <jonathan.protzenko@gmail.com> wrote:
You can use equirecursive types, which can be enabled through the -rectypes= command-line switch. With that option, your example above type-checks. How= ever, these are not enabled by default for a variety of reasons, the most i= mportant one being it makes it much easier to shoot yourself in the foot.
Cheers,

jonathan


On Sat 10 Sep 2011 01:14:46 AM CEST, Anthony Tavener wrote:
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 rec a () =3D printf "state a\n"; b
=A0 =A0 =A0 and b () =3D printf "state b\n"; a

Error: This expression has type unit -> unit -> 'a
=A0 =A0 =A0 but an expression was expected of type 'a


Is there a way I can do this? To express (or 'hide') the cyclic nat= ure of the type resolution?

I've considered using continuations, but that seems heavy-weight for wh= at 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 aro= und -- but for a task worthy of it!).

I can use a variant to represent states/modes and have a dispatcher which r= uns the right code... but this introduces what feels like an unnecessary la= yer of distraction. Returning the closure of the "next state" see= ms straightforward, but introduces cycles into the typing. :(

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

=A0-Tony


--00151740271ac8c68804ac8ba160--