I try to print the resullt of an List.Assoc.find function.
But for the code:
open Core;;
let convert_int_option x:int=match x with
| Some x → 1
| None → 0;;
Printf.printf “%d” ((convert_int_option (List.Assoc.find assoc “two”)));;
The compiler is giving the error:
Printf.printf “%d” ((convert_int_option (List.Assoc.find assoc “two”)));;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type
equal:(string → string → bool) → int option
but an expression was expected of type 'a option
let assoc=[("one",1);("two",2)] in
let mytoint x = match x with
| Some c -> c
| None -> 0 in
let comparestrings x y=
let z=String.compare x y in
if z=0 then true
else false in
let v=List.Assoc.find assoc ~equal:(fun x y -> comparestrings x y) "two" in
Printf.printf "%d" (mytoint v);;