epicours/Exam.md

22 lines
430 B
Markdown

## Multiple insertion
```
# let insert_mult n x lst =
if n <= 0 then
invalid_arg "insert_mult: n must be > 0"
else
let rec aux count = function
| [] -> []
| e::t ->
if (count = n) then
e :: x :: aux 1 t
else
e :: aux (count + 1) t
in
match lst with
| [] -> []
| z::f -> z :: aux 0 f
val insert_mult: int -> 'a -> 'a list -> 'a list = <fun>
```