Update docs
This commit is contained in:
parent
74e8064a1b
commit
059059ac87
@ -482,6 +482,25 @@ function g(p : int * option(int)) : int =
|
|||||||
b
|
b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Guards are boolean functions that can be used on patterns in both switch
|
||||||
|
statements and functions definitions:
|
||||||
|
|
||||||
|
```sophia
|
||||||
|
function get_left_if_positive(x : one_or_both('a, 'b)) : option('a) =
|
||||||
|
switch(x)
|
||||||
|
Left(x) | x > 0 => Some(x)
|
||||||
|
Both(x, _) | x > 0 => Some(x)
|
||||||
|
_ => None
|
||||||
|
```
|
||||||
|
|
||||||
|
```sophia
|
||||||
|
function
|
||||||
|
get_left_if_positive : one_or_both('a, 'b) => option('a)
|
||||||
|
get_left(Left(x)) | x > 0 = Some(x)
|
||||||
|
get_left(Both(x, _)) | x > 0 = Some(x)
|
||||||
|
get_left(_) = None
|
||||||
|
```
|
||||||
|
|
||||||
*NOTE: Data types cannot currently be recursive.*
|
*NOTE: Data types cannot currently be recursive.*
|
||||||
|
|
||||||
## Lists
|
## Lists
|
||||||
|
Loading…
x
Reference in New Issue
Block a user