From 27e21705457398bcd223f6b5a52a9938d135144a Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Fri, 20 Aug 2021 15:56:30 +0300 Subject: [PATCH] Update docs and changelog --- CHANGELOG.md | 2 +- docs/sophia_features.md | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b1b09..5028a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Set` stdlib - `Option.force_msg` - Loading namespaces into the current scope (e.g. `using Pair`) -- Assign patterns to variables +- Assign patterns to variables (e.g. `let x::(t = y::_) = [1, 2, 3, 4]` where `t == [2, 3, 4]`) ### Changed ### Removed diff --git a/docs/sophia_features.md b/docs/sophia_features.md index d6d062b..263eb12 100644 --- a/docs/sophia_features.md +++ b/docs/sophia_features.md @@ -471,6 +471,17 @@ function get_left(Both(x, _)) = Some(x) ``` +Sophia also supports the assignment of patterns to variables: +```sophia +function f(x) = switch(x) + h1::(t = h2::_) => (h1 + h2)::t // same as `h1::h2::k => (h1 + h2)::h2::k` + _ => x + +function g(p : int * option(int)) : int = + let (a, (o = Some(b))) = p // o is equal to Pair.snd(p) + b +``` + *NOTE: Data types cannot currently be recursive.* ## Lists