Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 531

OCaml - a function which returns all the prefixes of a list

$
0
0

For [1;2;3] , I want to return [[]; [1]; [1; 2]; [1; 2; 3]] . I have hit a wall and i need help, this is what i have done so far

let rev list =  let rec aux acc = function    | [] -> acc    | h::t -> aux (h::acc) t in  aux [] listlet prefixes xs =   let xs = rev xs in  let rec xs = function    | [] -> [[]]    | hd::tl -> xs::tl in  xs

Please help me, I know that probably most of what i have done so far is wrong.


Viewing all articles
Browse latest Browse all 531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>