Skip to content
Playground(another site)

bynk.types.negative_length

Error A length predicate was given a negative value.

MinLength, MaxLength and Length count the characters of a string, and a length cannot be below zero, so MinLength(-1) would hold for every string and MaxLength(-1) for none. The compiler takes a negative argument to be a mistake and refuses it. Give a length of zero or more. A set of predicates that no value can satisfy is bynk.types.empty_refinement.

Example

type Short = String where MinLength(-1) // ✗ a length is never negative
type Short = String where MinLength(8) // ✓

In the Book

See also

  • The grammar rule it governs: refinement.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.negative_length shows the same from the installed toolchain, without a network.