ocaml - Warning 8: Incomplete pattern matching warning in a let statement -
i pattern matching in let statement, know shape of result. clear cannot expect compiler infer knowledge, perhaps there's more idiomatic way in concise way.
as example, please @ following code:
type foo = of int | b of string let x = (true, 0) let (b, i) = x in + 2
which correctly warns me, result of (_, b _)
not matched. possible way explicitly handle missing case in:
let (b,i) = match x | (a, j) -> (a,j+2) | _ -> failwith "implementation error!"
but obscures actual computation. there more concise alternative?
edit: jeffrey scofield remarked in case without nesting, explicit conversion function work out well. there version nested type matching?
if sure right case , using ocaml 4.02 or higher, can add [@@warning "-8"]
declaration.
see the ocaml manual more details on attributes.
on previous versions of ocaml, can disable warning respect whole file (this depends on building workflow) or use explicit pattern matching described in jeffrey scofield's answer.
i advise against "disable warning on whole file" though, obscure other incomplete pattern matching may break code in unexpected ways in present (which easy spot)... or somewhere in future (like, if change type match on in later upgrade).
Comments
Post a Comment