r/functionalprogramming • u/zweiler1 • Jun 30 '26
Question Algebraic Shape Composition in a tiny functional language
/r/Compilers/comments/1ujv6kn/algebraic_shape_composition_in_a_tiny_functional/
10
Upvotes
View all comments
Show parent comment
3
u/unqualified_redditor Jul 02 '26 edited Jul 02 '26
Ok so you are doing pretty bog standard structural typing. i was imaging you might be doing something where you elaborate both types to
Identity<T> | Unitas the generic "shape" of both type declarations making them type check as the same thing.If your core AST has
Unit,Void,Sum, andProductbase types then you could elaborate any (non-recursive) ADT into a composition of them. If you had Iso-Recursive types then you can also do the same for recursive types. For example, a linked list becomesmu r. Unit | (a, r).I would encourage you to read Types and Programming Languages by Benjamin Pierce. It will help you A LOT with this exploration.
EDIT: I see your edit to the original post now. I'm not sure where the row polymorphism is coming in. The Point2D/Point3D example doesn't seem to demonstrate it. I would guess if anything what you have is more an example of record subtyping then row polymorphism but its hard to say from the snippet whats going on.