janestreet / base

Standard library for OCaml
MIT License
848 stars 124 forks source link

Core.List.exists doesn't work as expected #134

Closed nyinyithann closed 2 years ago

nyinyithann commented 2 years ago

I am not sure if i miss something or it's a bug.

open Core;;
List.exists ["a"; "b"; "c"] ~f:(fun  x -> x = "a");; 
Error: This expression has type string but an expression was expected of type int

List.exists [1; 2; 3] ~f:(fun x -> x = 3) works fine.

List.existsi also gives me the same error on string list.

Even the following code gives me the same error message if i open Base or Core in Utop.

open Core;;
let exists t ~f =
  let rec loop  t =
    match t with
    | [] -> false
    | hd :: tl -> f hd || loop tl
  in
  loop t ;;

exists ["a"; "b"; "c"] ~f:(fun  x -> x = "a") ;;

Test Environment 1: OS: macOS Catalina version 10.15.7 OCaml: 4.14.0 Utop: 2.9.2

Test Environment 2 (newly installed machine): OS: Utuntu 22.04 OCaml: 4.14.0 Utop: 2.92

base_list_exists_ubuntu

base_list_exists_mac
nyinyithann commented 2 years ago

my bad... i need to use String.equal.

List.exists lst ~f:(fun x -> String.equal x "a");;