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