Closed lachlansneff closed 1 year ago
Thank you for submitting this RFC, @lachlansneff! We have extensively discussed it during the 2023-02-20 weekly meeting; see the transcript.
The resolution was close, as there are several major concerns with this RFC:
Op.Add(42)
returns a view of a Signal
with 42
included in the reset value, or a Const
. If it is the latter, we do not currently have precedent for such polymorphism. (by @jfng)match
construct. The equivalent of e.g. match x { Foo { a: A(y), b: B(z) } => ... }
in Rust would require three nested matches to bind all the variables, and six levels of indentation. Similarly, the RFC does not explain how constructing variants where the payload is a structure would work; if the answer to point (2) is that it returns a Const
, then how is the type of the return value determined when the payload is a structure?data
field could be valid only if length != 0
. (by @rroohhh)A follow-up RFC that proposes a general purpose pattern matching construct and addresses all of the concerns raised during the meeting could be useful. However, it is not clear that such a construct can be implemented within the constraints of Python.
Discriminated Unions / Enums
This (sub)RFC builds on #697. As proposed in #697, first-class discriminated unions could be very useful.
Motivation
While discriminated/tagged unions can be built on top of
data.Struct
anddata.Union
, first-class support may improve readability and correctness of code.Overview and Examples
Detailed Design
This subRFC proposes several language and library additions:
data.Enum
class.Module
:m.Match
andm.IfLet
.Alternatives
amaranth.hdl
andamaranth.lib
.Open Questions
Enums
?Enum
a good name for this? It conflicts with the built-inenum.Enum
.DiscriminatedUnion
orTaggedUnion
would both be precise, but they're pretty wordy.