Update docs

This commit is contained in:
Gaith Hallak 2021-09-02 13:02:18 +03:00
parent 74e8064a1b
commit 059059ac87

View File

@ -482,6 +482,25 @@ function g(p : int * option(int)) : int =
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.*
## Lists