How to generate recursive list in OCaml
问题 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 l = a::b::c::l in l cycle 1 2 3 generates recursive list 1, 2, 3, 1... But, how to generate recursive list on basis of another regular list? let cycle lst = ... Usage cycle [1;2;3] 回答1: In an eager language like ML, you need to use streams. For example # let cycle = Stream.from (fun n -> Some (List.nth [1;2;3] (n mod 3)));; val cycle : int Stream.t =