This commit is contained in:
Gaith Hallak 2021-10-18 12:32:58 +03:00
parent 303ca21317
commit 6fa6dfbbc0

View File

@ -490,7 +490,7 @@ statements and functions definitions. If a guard expression evaluates to
will be checked: will be checked:
```sophia ```sophia
function get_left_if_positive(x : one_or_both('a, 'b)) : option('a) = function get_left_if_positive(x : one_or_both(int, 'b)) : option(int) =
switch(x) switch(x)
Left(x) | x > 0 => Some(x) Left(x) | x > 0 => Some(x)
Both(x, _) | x > 0 => Some(x) Both(x, _) | x > 0 => Some(x)
@ -499,10 +499,10 @@ function get_left_if_positive(x : one_or_both('a, 'b)) : option('a) =
```sophia ```sophia
function function
get_left_if_positive : one_or_both('a, 'b) => option('a) get_left_if_positive : one_or_both(int, 'b) => option(int)
get_left(Left(x)) | x > 0 = Some(x) get_left_if_positive(Left(x)) | x > 0 = Some(x)
get_left(Both(x, _)) | x > 0 = Some(x) get_left_if_positive(Both(x, _)) | x > 0 = Some(x)
get_left(_) = None get_left_if_positive(_) = None
``` ```
Guards cannot be stateful even when used inside a stateful function. Guards cannot be stateful even when used inside a stateful function.