I would like to implement analog of Haskell cycle
function.
If I pass list elements explicitly it seems trivial:
let cycle a b c =
let rec
You need streams as in another answer, or lazy lists:
type 'a llist = LNil | LCons of 'a * 'a llist Lazy.t
let cycle = function
| [] -> invalid_arg "cycle: empty list"
| hd::tl ->
let rec result =
LCons (hd, lazy (aux tl))
and aux = function
| [] -> result
| x::xs -> LCons (x, lazy (aux xs)) in
result