4 ms·
I don't know that anyone has really solved that problem: http://lambda-the-ultimate.org/node/4170 http://lambda-the-ultimate.org/node/4170 Honestly, maybe the
by wtetzner 11y ago
I don't know that anyone has really solved that problem:
http://lambda-the-ultimate.org/node/4170 http://lambda-the-ultimate.org/node/4170
Honestly, maybe the solution is just to look at the problem a different way, and use an attribute grammar instead, like Ted Kaminski mentioned.
- jasim 11y agoAsking as a complete layperson, are there any other strongly typed languages that doesn't have this issue when parsing an AST and adding metadata during subsequent passes?
- wtetzner 11y agoWell, in ML you can easily create an AST type that allows you to add metadata as you go, by using option types. The problem is that what you really want is to have multiple representations of the AST, each only supporting relevant data. You could potentially solve the problem using macros, to generate different versions of the AST, but it doesn't solve the problem of having multiple ASTs. I suppose you could parameterize your type with whatever metadata should be on it, which means you only have to create one tree. But then pattern matching on it becomes a little bit messier, and your type is a bit more complicated. So it's not that the problem doesn't have any solutions at all, it's just that none of them are totally satisfactory. The reason you don't have this problem in untyped languages is that you aren't trying to type them :). The first solution I mentioned, using option types, is effectively how you would handle it in a dynamic language.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- sklogic 11y agoI think I found a relatively sane solution to the expression problem, which employs quite a weird type system. The trick is to use a permissive (nearly "dynamic") first typing pass, using a "weak set" unification (a special kind of a Prolog variable which unifies with any other weak set, merging the values together), and then doing another typing pass to find out of the union types inferred this way are isomorphic to the expected declarations. This way, tagged unions can be expanded, cut down, rewritten using simple rules - all the stuff you can do in Nanopass, but strictly typed with a Hindley-Milner type inference.