Re: [Caml-list] Mutually recursive closures?

2011-09-10 Thread Philippe Veber
You may not need the -rectypes option if you add a thin layer around your functions: Objective Caml version 3.12.1 Findlib has been successfully loaded. Additional directives: [...] # type t = F of (unit - t);; type t = F of (unit - t) # let rec a = F (fun () - print_endline a ; b) and

Re: [Caml-list] Mutually recursive closures?

2011-09-10 Thread Anthony Tavener
That's a good alternative, thanks Philippe! I might use this, but encapsulate the returned closures with the constructor since they will be of common type -- whereas the function signatures will be different, some having additional parameters. I've read more on rectypes and it's certainly not to

[Caml-list] Mutually recursive closures?

2011-09-09 Thread Anthony Tavener
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 () =

Re: [Caml-list] Mutually recursive closures?

2011-09-09 Thread Jonathan Protzenko
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

Re: [Caml-list] Mutually recursive closures?

2011-09-09 Thread Anthony Tavener
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