From 9137e43f906718a12da8bd3640e4645f4924d431 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Mon, 26 Aug 2024 16:25:57 +0000 Subject: [PATCH] Update Examples --- Examples.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Examples.md b/Examples.md index 6f47cfc..cc2afc3 100644 --- a/Examples.md +++ b/Examples.md @@ -986,4 +986,22 @@ fn main ``` - \ No newline at end of file + + +#### match +There's not really much new Husht-syntax-wise in this section. However, it does raise the challenge of destructuring a nested struct. Suppose Foo has fields bar of type Bar and baz of type Baz, and further each of Bar and Baz have fields x and y. Then the full destructure of a Foo might look like: +``` +let Foo bar: Bar x: x1, y: y1, baz: Baz x: x2, y: y2 = aFoo +``` +Is this really parseable? It seems not; what if Bar also had a Baz field named baz? There's no way for the parser to tell short of analyzing the types. So it seems some braces or linebreaks are necessary. Husht will allow either of course. So you could write: +``` +let Foo bar: Bar {x: x1, y: y1}, baz: Baz x: x2, y: y2 = aFoo +``` +or +``` +let Foo + bar: Bar x: x1, y: y1 + baz: Baz x: x2, y: y2 + = aFoo +``` +as the spirit moves you. \ No newline at end of file