Right now, I have a nested pattern match that behaves strangely.
Here is a snippet of code
match setting with
| "-f" | "--file" -> // Open file
({ state with file = Some (cur_dir + "\\" + elem) }, "")
| "" -> // Option without parameter
match elem with
| "-h" | "--help" -> // Display help message
({ state with help = true }, "")
| "-r" | "--readonly" -> // Open with readonly
({ state with readonly = true }, "")
| opt -> (state, opt)
| _ -> (state, "") // Ignore invalid option
Unfortunately, I get two warnings when compiling the above code. One claims that the final template template is not available. Another states that the first matching statement is incomplete.
These two warnings seem to contradict each other, and if I add in parentheses to make the expression more understandable, the warnings disappear and my code works correctly.
match setting with
| "-f" | "--file" -> // Open file
({ state with file = Some (cur_dir + "\\" + elem) }, "")
| "" -> // Option without parameter
( match elem with
| "-h" | "--help" -> // Display help message
({ state with help = true }, "")
| "-r" | "--readonly" -> // Open with readonly
({ state with readonly = true }, "")
| opt -> (state, opt) )
| _ -> (state, "") // Ignore invalid option
My question is: what happened to the source code? This was not a case of an incorrect bracket, and it seems that this should be obvious to the compiler, where each match ends.
Edit: here is the full function if it helps
let process_args argv =
let (result, _) = ((default_settings, "-f"), argv) ||>
Array.fold (fun (state, setting) elem ->
match setting with
| "-f" | "--file" ->
({ state with file = Some (cur_dir + "\\" + elem) }, "")
| "" ->
match elem with
| "-h" | "--help" ->
({ state with help = true }, "")
| "-r" | "--readonly" ->
({ state with readonly = true }, "")
| opt -> (state, opt)
| _ -> (state, "")
) in
result
, , .
Edit2: , . .