Skip to content

Allow more complex pattern matching in match statement #240

@schoen

Description

@schoen

Project

core

Describe the feature

According to https://docs.simplicity-lang.org/simplicityhl-reference/match_expression/

Match expressions don't support further pattern matching, in contrast to Rust.

For example, we can't destruct a tuple by matching its elements inside the match statement.

I think it would be good to be able to do this and developers would appreciate it (and expect it by default, if they're coming from Rust).

An example that I wanted to be able to do with tuple destructuring that doesn't work:

// We already know that the None case here cannot happen because
// num_outputs() is exactly 2.
let (out_asset, out_amount): (Asset1, Amount1) = match jet::output_amount(0) {
    Some((myasset, myamount): (Asset1, Amount1)) => (myasset, myamount),
    None => (0, 0),
};

We are instead allowed to do this:

let (out_asset, out_amount): (Asset1, Amount1) = unwrap(jet::output_amount(0));

This may actually be closer to what I want in this case because the None branch should be impossible, but in general I would like to be able to assign the elements of the tuple inside of the match.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions