BlockstreamResearch / simfony

Rust-like high-level language that compiles down to Simplicity bytecode. Work in progress.
26 stars 9 forks source link

Array patterns #17

Closed uncomputable closed 6 months ago

uncomputable commented 7 months ago

Enable destructing of arrays in let statements let [a, b,c] = (1, 2, 3), using array patterns. Do some refactors beforehand.

apoelstra commented 7 months ago

As a terminology note. I think we should use the term "structural types" rather than "base types" or "Simplicity base types". This is easier to understand because it's a more unique name and describes exactly what they are (types which are defined by their structure, i.e. their pattern of sums and products).

In future we probably want a tighter distinction between these, so that it's no longer possible to e.g. assign an array literal to a manually-constructed tree of products, and so that it's possible for users to define types like Celsius and Farenheit and Simfony will prevent assigning between them. We could introduce a cast operator which would check that two types were structurally equal and refuse to compile otherwise.

But this may be out of scope for 1.0. (Although within 1.0, we may want to introduce more rigor into this codebase by distinguishing between Simfony types and inserting casts when they are needed.) For now let's at least use the "structural type" terminology though.

apoelstra commented 7 months ago

This comment mostly applies to 4a10d48b767c09a53243e12fcde7964eb5ff3c84 "Pattern: convert to base".

apoelstra commented 7 months ago

Done reviewing f3d4d2534fcd651923938af49f22441841354a90. Will ACK though I leave it up to you whether you want to address my comments here or in a followup PR.

uncomputable commented 7 months ago

For now I updated BinaryTree to include a private enum.