Hi Eric,

I tried to do something like that some times ago, while my concern was about some tricky recursive module definition, i think the problem was the same : the chicken-egg one. Your docycle is trying to define something it must already know and the problem can't be escaped for evaluation order prevents any value to be recursive at definition time. The recursivity can be achieved by using a second construction pass that corresponds to additional properties (lazyness or mutability or hacking through Obj). Those properties will necessarily occur either explicitly (like OCaml) or implicitly (like in Haskell).

So, the real question, as far as i understand your problem, is : are you asking how to hide those properties in OCaml or to see if you need to ask your purchasing department some quantum computer that can predict the address of a future allocated block ? ;)
 
-- Julien


2012/12/18 Eric Jaeger <eric.jaeger@ssi.gouv.fr>

Hi everyone,

 

There are various discussions on recursive lists in the archive, yet I was wondering whether or not it was possible in pure OCaml to write a function returning non-constant recursive lists.

 

For example, I would like to have a function “docycle:’a list->’a list” that takes a non recursive list and transforms it into a recursive list containing the same elements. That is, “docycle [1;2;3]” would return a list structurally equivalent to “let rec c=1::2::3::c in c”. So far, my various attempts (OCaml 3.12) have not been successful. Another good example is to have a List.map compatible with recursive lists.

 

Please note that it is, in a way, a theoretical (and possibly naïve) question :

-          I do not consider recursive lists as the perfect implementation for my problem

-          I do not care about efficiency

-          I do not want to use an ad hoc mutable/lazy list datatype (unless I’ve also a conversion function toward standard lists)

-          I do not want to use Obj or other similar tricks

It’s just that I’m curious whether or not what I’m trying to achieve is possible.

 

  Regards, Eric