Exercise : Do not confuse 'match' and 'function'
- Does the following function confused2 have type int × bool → int?
let confused2 (a,b) = function | (0, true) -> 1 | (n ,_) -> 10
Apply confused2 in order to obtain 1. Try again to obtain 10. - Guess the types of both functions:
let foo x y = match (x,y) with | (0,0) -> x | _ -> y
let bar x y = function | (0,0) -> x | _ -> y
- Conclusion: be careful with
match
andfunction
.