3 ms·
The duplication there in each AST node kinda hurts the eyes :) Also, the type-switch on interface {} is ugly. Consider how an AST looks like in Haskell: da
by Peaker 12y ago
The duplication there in each AST node kinda hurts the eyes :)
Also, the type-switch on interface {} is ugly.
Consider how an AST looks like in Haskell:
data AST
= LiteralInt Int
| LiteralFloat Float
| List [AST]
...
And then an eval looks like:
case ast of
LiteralInt int -> ...
LiteralFloat float -> ...
List nodes -> ...
and it is safe, rather than interface{}, you get the AST type and you get exhaustiveness checking that you covered all cases.
Also, if you add an annotation to each AST element (e.g: inferred types), you can very easily and safely map over them, etc.