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
2
u/zweiler1 Jul 02 '26 edited Jul 02 '26
I updated the original post, yes it's all just structural typing with nothing special about it, as I now understand...
No, those types are not equal, their tag names differ. Two sum types are "equal" when all their tags and payload types match up.
Yes there exists a typing context,
Optionin your case describes a (unresolved / generic) sum type with the tagSomeof that unresolved typeTand a the tagNone. A sum type is, at the language level / interpreter, just a linked list of tags + optional payload types, and equivalence is determined by the tag name and type. So when the "type"Optionis encountered by the parser it just flattens it to it's underlying sum type, being just a linked list. The "type name" is completely eliminated in that phase, what stays is underlying structural type.Recursion is just implemented by adding the function symbol to it's own environment before executing it's body, the function itself is just seen like any other regular function of the program. Execution is implemented using trampolining, recursion blew up the host stack way too quickly.