I am new to ocaml and i am having trouble with i fuction that i am writing
I have to write a fuction that takes a list and returns a list of pairs of 1st and last element 2nd and 2nd last and so forth it doesnt matter if list has odd or even num of elements.
The idea i have is to declare another function inside this function that takes to lists as input original list and its revers .but i cant seem to figure out how to correctly write the function
Here is the code
let rec lip l =
match l with
| [] -> []
| h::_ -> let rec w (l ,l1 ,i) =
let l1=List.rev l in let i =2 in
if (List.length l)/i > 0 then
[(List.hd l ,List.hd l1)]@w(List.tl l,List.tl l1 ,(i+1))
else []
this is how far i managed to write it
theoretically this idea should work but as i am a beginner i have a hard time with the syntax and a looked for simmilar examples and tutorials but didnt find what i needed
ps.if the list has odd number of elements the middle one is ignored