From 15ddec00bdc4f8f34f671f70541b457cc7ce5a39 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Sat, 18 Sep 2021 18:33:07 +0300 Subject: [PATCH] Elaborate on guards --- docs/sophia_features.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/sophia_features.md b/docs/sophia_features.md index 48e6c8a..246ac14 100644 --- a/docs/sophia_features.md +++ b/docs/sophia_features.md @@ -471,6 +471,8 @@ function get_left(Both(x, _)) = Some(x) ``` +*NOTE: Data types cannot currently be recursive.* + Sophia also supports the assignment of patterns to variables: ```sophia function f(x) = switch(x) @@ -482,8 +484,10 @@ 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: +Guards are boolean expressions that can be used on patterns in both switch +statements and functions definitions, if a guard expression evalutaes to +`true`, then the corresponding body will be used, otherwise, the next pattern +will be checked: ```sophia function get_left_if_positive(x : one_or_both('a, 'b)) : option('a) = @@ -501,7 +505,7 @@ function get_left(_) = None ``` -*NOTE: Data types cannot currently be recursive.* +Guards cannot be stateful even when used inside a stateful function. ## Lists