Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 527

this pattern-matching is not exhaustive in OCaml

$
0
0

I am new in OCaml and I wrote some code to get the n element of a list

let rec n_elem l n = match n with| 0 -> match l with    | h::_ -> h    | _ -> failwith "erorr with empty list"| _ -> match l with    | h::t -> n_elem t (n-1)    | _ -> failwith "erorr with empty list";;

When I run it using ocaml interpreter, an warning generate as:

Warning 8: this pattern-matching is not exhaustive.Here is an example of a value that is not matched:1Warning 11: this match case is unused.

and when I run it with:

Printf.printf "%s\n" (n_elem ["a";"b";"c";"d"] 1);;

it generate match_failure...

Could anyone give me some help?


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>