Skip to content

Instantly share code, notes, and snippets.

View nicolasboulay's full-sized avatar

Nicolas Boulay nicolasboulay

  • Nice area, France
View GitHub Profile
@nicolasboulay
nicolasboulay / gist:a8ee4a65e8c2cc110c20e6d24e838e86
Last active October 11, 2017 14:57
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.