Skip to content

Documentation/implementation mismatch for List.exists2_exn etc. #16

@yallop

Description

@yallop

I've been migrating some list-processing code to use Core_kernel instead of the standard library and noticed that the documentation strings for the two libraries have somehow become interchanged. The standard library documentation for List.exists2 says:

Same as List.exists, but for a two-argument predicate. Raise Invalid_argument if the two lists have different lengths.

In fact, List.exists2 does not always raise Invalid_argument if the two lists have different lengths:

# List.exists2 (>) [1; 2] [3; 1; 0];;
- : bool = true

On the other hand, the documentation for Core.Std.List.exists2_exn says:

Same as List.exists, but for a two-argument predicate. Raise Invalid_argument if the end of one list is reached before the end of the other.

In fact, Core.Std.List.exists2_exn can fail even if the predicate is satisfied (which should mean that the ends of the lists are not reached):

# Core_kernel.Std.List.exists2_exn ~f:(>) [1; 2] [3; 1; 0];; 
Exception: Invalid_argument "length mismatch in exists2_exn: 2 <> 3 ".

I'd submit a pull request fixing the documentation (as for the standard library), but wonder if the implementation might be changed instead. It seems a bit inefficient to traverse both lists before starting when the function is supposed to be short-circuiting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions