You can make your code a little cleaner like this:
match n < 0 with | true -> [] | false -> [x] @ clone x (n - 1)
Even better:
if n < 0 then [] else [x] @ clone x (n - 1)
Generally, if the statements are more understandable than the correspondences for simple logical tests.
While we are doing this, we can use :: instead of @ :
if n < 0 then [] else x :: clone x (n - 1)
source share