I was trying to unwrap the result of List.max_elt
of a non-empty list, which should always exist, so I thought Option.value_exn
would be the correct tool. But it fails with a strange error:
# List.range 0 10 |> List.max_elt ~cmp:compare;;
- : int option = Some 9
# Option.value_exn (Some 9);;
- : int = 9
# List.range 0 10 |> List.max_elt ~cmp:compare |> Option.value_exn;;
Error: This expression has type
?here:Lexing.position ->
?error:Base.Error.t -> ?message:string -> 'a Base.option -> 'a
but an expression was expected of type int option -> 'b
Can anybody explain this error to me?
I'm using OCaml 4.05.0 and the latest Core library.