I have a function defined like this:
let test_func lis =
match lis with h::t ->
match h with h2::t2 ->
h2
| [] ->
[]
| [] ->
[];;
When compiled, I get a warning that this function does not match the pattern [] - even though I defined it as the second case! I have found that I can fix this by surrounding the second match statement with parens:
let test_func lis =
match lis with h::t ->
(match h with h2::t2 ->
h2
| [] ->
[])
| [] ->
[];;
but I was wondering why this is necessary. In addition, swapping the first and second case in the top level match statement also works:
let test_func lis =
match lis with [] ->
[]
| h::t ->
match h with h2::t2 ->
h2
| [] ->
[];;
Thanks!
begin ... end
instead of parens. It's much easier to discern the blocks of code. – nlucaroni