Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let destructuring of records #118

Open
giacomocavalieri opened this issue Jul 26, 2024 · 5 comments
Open

let destructuring of records #118

giacomocavalieri opened this issue Jul 26, 2024 · 5 comments

Comments

@giacomocavalieri
Copy link
Member

I couldn't find it anywhere I think the tour is never showing how one could destructure a record like this:

pub type Wibble {
  Wibble(a: Int, b: String)
}

let Wibble(a: one, b: other) = Wibble(1, "a")
@lpil
Copy link
Member

lpil commented Jul 26, 2024

We've been explaining patterns entirely with case, to do it with let too for each case would be explaining each type of pattern twice. How could we communicate this clearly without saying everything twice?

@giacomocavalieri
Copy link
Member Author

giacomocavalieri commented Jul 26, 2024

The record pattern matching section already explains it as

The let keyword can only match on single variant custom types. For types with more variants a case expression must be used.

I think it would be nice to add a code example showcasing it in this section or one might be left wondering what "using the let keyword" means here

@giacomocavalieri giacomocavalieri changed the title let restructuring of records let destructuring of records Jul 26, 2024
@lpil
Copy link
Member

lpil commented Jul 28, 2024

Do you have thoughts on my point above?

@giacomocavalieri
Copy link
Member Author

giacomocavalieri commented Jul 29, 2024

How could we communicate this clearly without saying everything twice?

I'm not really sure 😬
I'd maybe add a standalone section on "let destructuring" after all the pattern explanations and say something along the lines of "on the left of a let you can write a pattern just like you would in a case expression" and show examples and how it limits to only patterns that are guaranteed to match

@lpil
Copy link
Member

lpil commented Jul 29, 2024

Okie! Let's just add an example for records for now and worry about that later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants