Browse thread
Re: [Caml-list] forbidden construct as right hand side of "let rec"
-
Damien Guichard
- Marc de Falco
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Marc de Falco <marc.defalco@g...> |
| Subject: | Re: [Caml-list] forbidden construct as right hand side of "let rec" |
The issue is that this definition can't be generalized to lists of arbitrary size. The code let list_cycle l = let rec loop = l @ loop in loop will not be accepted. I don't know the exact rule, but I guess that on the right-hand side of a let rec defining a ground value named foo you can only write a term which evaluates to a finite ground term on the currently defined variables + foo. That is to say something that evaluates to a finite tree of constructors with constants or defined variables as leaves. Maybe someone more knowledgeable could state the exact rule. - marc P.S. : the code using Obj is far from a solution as it modifies the existing structure of the list to add cycling and thus, breaks persistency. Le 23 oct. 2009 à 17:35, Damien Guichard a écrit : > > let list_cycle2 a b = > let rec loop = a::b::loop > in loop > > > - damien > > En réponse au message > de : Lukasz Stafiniak > du : 2009-10-23 01:10:37 > À : caml-list > CC : > Sujet : Re: [Caml-list] forbidden construct as right hand side of > "let rec" > > While we are at it, what is the best way to convert a "straight" list > into a cyclic list? > > i.e. convert > > let l = a::b::[] > > into > > let rec l = a::b::l > > (for arbitrary length lists). (The answer I recall from the archives > was using Obj.magic to mutate the [] in the original list). > > On Fri, Oct 23, 2009 at 12:34 AM, Stéphane Glondu <steph@glondu.net > > wrote: > > Mathias Kende a écrit : > > > let rec g = f g > > > > What about: > > > > let rec g x = f g x > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs