Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sum type not always the best choice
When you came from the Ocaml world, tree and AST are easly done with a sum type. The sum type have the very nice feature of
not compiling if a case is missing, wich is super nice for code refactoring.
But a new kind of technique that only use module and function exist, it's called tagless final. Module are kind of golang package
with parameters. It's look like mother class but with types as parameters.
So you use simple function call to describe an ast, then you could interpret it the way you want. Typical examples are
type checking, pretty print and execution.
I don't think it's possible to do it in Golang with interface and struct because of the lack of type as parameter.
Maybe if a package could be created at compile time with some parameter, the technique became possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.