ocaml.lang.performance.list.ocamllint-length-more-than-zero

Author
4,866
Download Count*
License
You probably want $X <> [], which is faster.
Run Locally
Run in CI
Defintion
rules:
- id: ocamllint-length-more-than-zero
pattern: List.length $X > 0
message: You probably want $X <> [], which is faster.
languages:
- ocaml
severity: WARNING
metadata:
category: performance
technology:
- ocaml
license: Commons Clause License Condition v1.0[LGPL-2.1-only]
Examples
list.ml
let test xs =
(* ruleid:ocamllint-length-list-zero *)
if List.length xs = 0
then 1
else 2
let test2 xs =
(* ruleid:ocamllint-length-more-than-zero *)
if List.length xs > 0
then 1
else 2
Short Link: https://sg.run/gLZ5