It's me again, trying to win a fight with OCaml and loosing really bad.
Now I'm working with Lazy Lists,
so this is my set-up
(*setup*) type 'a lazy_list = LNil | LCons of 'a * (unit -> 'a lazy_list);; let rec lfrom k = LCons (k, function () -> lfrom (k + 1));; let rec ltake = function (0, xq) ->  | (n, LNil) ->  | (n, LCons (x, xf)) -> x :: ltake (n - 1, xf());;
and now I'm trying to make a function that takes a lazy list, and returns a lazy list with every element duplicated n times (exp.n=3 [1,2,3]->[1,1,1,2,2,2,3,3,3] but it should be lazy). So it's somthing like int -> 'a llist -> 'a llist.
After modifying other function, I have something like that:
let lreapt n llist1= let rec ljoin llist1 llist2 = match llist1 with | LNil -> llist2 | LCons (x, xf) -> LCons (x, function () -> ljoin (xf()) llist2) in let rec lduplicate k item = match k with | 0 -> LNil | _ -> LCons (item, function () -> lduplicate (k-1) item) in match llist1 with | LNil -> llist1 | LCons (x, xf) -> LCons (x, function () -> ljoin (lduplicate n x) (lrepeat n (xf())))
and an error: This expression has type int but an expression was expected of type
int -> int.
But i'm pretty sure, that not the error but the fact, that my idea is broken in some way, is the biggest issue.
I just can't get a grasp on functional programming.