3 ms·
I'd love to hear more detail about the example you give of type inference over an AST. I like the idea, but I'm having trouble envisioning how to write code in
by swift 9y ago
I'd love to hear more detail about the example you give of type inference over an AST. I like the idea, but I'm having trouble envisioning how to write code in that style cleanly. Did you implement that in an open source project I could take a look at?
- evincarofautumn 9y agoIt’s not the prettiest code, but here: https://github.com/evincarofautumn/kitten/blob/8a7e949f1af71384a5fb56693de32474dead492c/new/lib/Kitten/Infer.hs#L123 https://github.com/evincarofautumn/kitten/blob/8a7e949f1af71... The key line is: (term', t, tenvFinal) <- inferType dictionary tenvFinal' tenv term In “inferType”, I just annotate each term with “Zonk.type_ tenvFinal type_” as I go, in the same pass as generating the type constraints. Since “tenvFinal” is the final type environment, and “zonking” substitutes all type variables with their solved types, everything gets lazily resolved when reading the annotated types later on, e.g., during analysis & codegen.
- swift 9y agoThanks, that helped me understand better. That's really cool!