my goal is to write a times function of type int list -> int
that that takes a list of int
s and, using continuations, returns an int
such that that int
= multiplication of all the int
s in the int list
.
for instance times [2;2;3]
returns 12
.
Here is what I have so far:
let times l =
let rec times' l c = match l with
| [] -> c []
| h::h2::t -> times' (h*h2::t) (fun r -> c ( r))
| h :: [] -> times' [] (fun r -> c (h::[]))
in
times' l (fun r -> r) ;;
Problems with my code
it returns an int list with one element which is the result (multiplication of all
int
s in the inputedint list
)I feel like this is not really using continuations, this seems to be a normal tail recursive function but I am not sure since I am still not very familiar with this programming style.