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

Popular posts from this blog

php - How to build a web site which gives a sub-domain dynamically to every registered user? -

c# - Add item to Generic List / Collection using reflection -