type.ordering_operand
A comparison such as < or > is used on a value that has no order, such as text or a value that may be none.
Area 3, Logic; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
<, <=, > and >= put two values in order, so they work only where
an order means something: numbers and time values of one named type. A
value that may be none has no place in an order, and Jadpo won't guess
whether none comes first or last. Text has no order either, because
the order depends on the reader's language.
What it looks like
main.jadpo:
type Count = Int {}type Flag = Bool {}function over_maximum(count: Count?, maximum: Count) -> Flag { return Flag(count > maximum)}
error count may be none, so it can't be ordered
--> main.jadpo:6:17
|6 | return Flag(count > maximum) | ^^^^^ may be `none`
- reason
countisCount?;<,<=,>and>=order two values, andnonehas no place in an order.- next
- Match on
countand compare insidesome(...)(agent) - rule
- type.
ordering_ operand - help
- https://jadpo.
dev/docs/errors/type. ordering_ operand
(agent) at the end of the next: line means your coding agent can make
the fix itself.
Comparing two pieces of text with < is the same error:
main.jadpo:
type Name = Text {}type Flag = Bool {}function earlier(name: Name, other: Name) -> Flag { return Flag(name < other)}
error Name has no order
--> main.jadpo:6:17
|6 | return Flag(name < other) | ^^^^ this is `Name`
- reason
- Text order depends on the reader's language, so
<,<=,>and>=work only on numbers and time values. - next
- Compare the text with
==, or order it with a standard-library function (agent) - rule
- type.
ordering_ operand - help
- https://jadpo.
dev/docs/errors/type. ordering_ operand
How to fix it
If the value may be none, match on it, compare inside
some(...), and say what the answer is when there is no value:
return match count { some(known) -> Flag(known > maximum) none -> false }
A count that is there is compared with the maximum, and a missing count is never over it.
If you are putting text in order, sort a list of it with
list.sort_by, giving the text as the key. main.jadpo becomes:
type Name = Text {}function in_order(names: List<Name>) -> List<Name> { return list.sort_by(names, name -> name)}
The names come back sorted by their code points, the same order a query
sorts text in. Given locale:, list.sort_by orders text by a
language's rules instead (Lists).
To check that two pieces of text are the same, compare them with ==.
Related
Markdown for agents: /docs/errors/type.ordering_operand.md.Built from Jadpo main at aee2e8f.