5.3 Annotations
[1, 2, 3]
If annot is a converter annotation, the conversion is applied before matching the converted value against bind. This dependency implies that the conversion in annot cannot be delayed, and must be performed as part of the matching process (before committing to the match).
annotation | |
| |
annotation | |
| |
annotation | |
| |
annotation | |
The None annotation matches no values, or in other words, is equivalent to Any.of(). It is useful for asserting that something never returns, such as a function that always throws.
#true
#true
#false
> "hello" :: Any.to_boolean
#true
> #false :: Any.to_boolean
#false
#false
#false
[1, 2, 3]
"oops"
If annot is a converter annotation, only the matching component of the annotation is used, and the converting part is not used. See also Annotations as Converters.
#true
#false
binding operator | |
| |
| |
binding operator | |
|
> def (x :: Int) described_as An Integer = "oops"
def: value does not satisfy annotation
value: "oops"
annotation: An Integer
def: value does not satisfy annotation
value: [9, 11]
annotation: matching([_, 10])
annotation | |
> 15 :: (satisfying(is_multiple_of(3))
&& satisfying(is_multiple_of(5)))
15
> [1, 2, 3] :: satisfying(is_list_with_one)
[1, 2, 3]
> Array(1, 2, 3) :: satisfying(is_list_with_one)
::: value does not satisfy annotation
value: Array(1, 2, 3)
annotation: satisfying(is_list_with_one)
annotation | ||||||||||||
| ||||||||||||
| ||||||||||||
|
When annot is provided, then its static information is propagated to the new converter annotation. If annot is supplied with ::, then the result of the body sequence is checked against annot.
See also Annotations as Converters.
def: value does not satisfy annotation
value: "eleven"
annotation: converting(fun (x :: Int): x + 1)
#false
"string"
::: value does not satisfy annotation
value: #true
annotation: maybe(String)
As a binding, bind!! matches non-#false values that match bind. Similar to the !! expression form, when static information for the input to bind!! is maybe(annot), then bind more specifically starts with the static information of annot.
> len("apple")
5
> len(#false)
0
> len(1)
len: argument does not satisfy annotation
argument: 1
annotation: maybe(String)
> len("apple")
5
> len(#false)
!!: claimed not false, but actual value is false
expression | |
| |
expression | |
| |
repetition | |
| |
repetition | |
When expr has static information from maybe(annot), then the argument to . has static information of annot. If the result of the . form in the non-#false case has static information like annot, then the overall ?. expression has static information like maybe(annot).
> len("apple")
5
> len(#false)
0