I'm trying to construct a list in OCaml only using List.map
, List.filter
, and anonymous functions.
What I want to get is this:
- : int list list = [[2; 2]; [5; 5; 5; 5; 5]; [7; 7; 7; 7; 7; 7; 7]; [3; 3; 3];2[12; 12; 12; 12; 12; 12; 12; 12; 12; 12; 12; 12]; [4; 4; 4; 4]; ... ]
from this list
let entiers = [2; 5; 7; 3; 12; 4; 9; 2; 11];;
What i've tried so far:
List.map (fun n acc -> acc = n if acc = 0 then [] else n :: fun n acc -1 ) entiers;;
But i'm getting a syntax error, so i'm kinded of stuck...
Can someone help me to solve this problem ?Thank you !