Enums#376
Conversation
80c3f02 to
d9205e1
Compare
3fe6c4a to
0e1da07
Compare
d9205e1 to
8eb51b5
Compare
0e1da07 to
c337076
Compare
8eb51b5 to
d671344
Compare
|
I do not have a complete understanding of Simplicity's type algebra, so I did a few iterations with Fable 5 to understand how it works Here is the summary: Simplicity's type algebra has exactly three constructors: the unit type The choice being canonical matters more than what the choice is. Four independent pieces of the compiler navigate this tree, and they only interoperate because all four recurse with the same split:
If any one of them split differently, a constructed Theoretical foundationFinite coproducts from binary ones. In type-theoretic terms an enum is a sum type; categorically, a coproduct Why nonempty (the panic). The empty coproduct is the initial object Injections and case analysis. A coproduct comes with injections The discriminant is the path. A Simplicity sum value is encoded as a tag bit choosing left/right, then the payload. So a variant's encoding starts with the sequence of tag bits spelling its root-to-leaf path — the path is the discriminant; no separate tag field exists. This is where "why balanced, not a right-nested comb
The exact shape. One last practical point hidden in the doc comment: when a value is constructed, only the leaf actually inhabited carries data — the types of all sibling subtrees along the path aren't determined by the injection itself. They get pinned by Simplicity's type inference when the value meets its consumer (the match's |
afafbd5 to
004260f
Compare
e89df73 to
e1e17f3
Compare
9422aba to
00c75ca
Compare
e1e17f3 to
a72da02
Compare
This PR is re implementation of #336 with the emphasis on nominative enums