3 ms·
Writing a language in Go, which doesn't have sum types won't be fun. Also, if you want to implement a compiler, and not an interpreter, the host language havin
by Peaker 12y ago
Writing a language in Go, which doesn't have sum types won't be fun.
Also, if you want to implement a compiler, and not an interpreter, the host language having GC is not very useful to get GC.
Haskell is going to make working with ASTs much easier and safer. It also has a superset of the concurrency features of Go.
- zik 12y agoI'm writing a language in Go. It is fun. Sum types (and ASTs) are implemented with interfaces which provide a pretty clean and type safe way of doing this.
- Peaker 12y agoCan you show some small example encoding of an AST in Go?
- rogpeppe1 12y agohttp://golang.org/pkg/go/ast/ http://golang.org/pkg/go/ast/ Well, not that small, i guess :-)
- stcredzero 12y agoThe code for Twik has a simple AST in it. Of course, it's Lisp, so it's perhaps too simple. http://blog.labix.org/2013/07/16/twik-a-tiny-language-for-go http://blog.labix.org/2013/07/16/twik-a-tiny-language-for-go
- Peaker 12y agoThe 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.