OCaml: Matching with any negative -
is there way pattern matching match value negative number? not matter negative number need match negative.
i have accomplished want simple code:
let y = if(n < 0) 0 else n in match y 0 -> [] | _ -> [x] @ clone x (n - 1)
but want eliminate if
statement , check case in match
statement
yes, use guard:
match n _ when n < 0 -> [] | _ -> [x] @ clone x (n - 1)
Comments
Post a Comment