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

Construct a list of sublists of N*N elements

$
0
0

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 !


Viewing all articles
Browse latest Browse all 531

Trending Articles



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