6.48 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 |
bind described_as term ... |
> 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)