Closed acl33 closed 3 years ago
Just as it's been on my mind: I've been wondering about explicitly removing the "decl" flag, and just making Defs and Lambdas explicitly mention a list of (Var, Type) pairs. This makes the AST much more accurately match the syntax, and would probably result in a lot of cleanup. Thoughts?
Just as it's been on my mind: I've been wondering about explicitly removing the "decl" flag, and just making Defs and Lambdas explicitly mention a list of (Var, Type) pairs. This makes the AST much more accurately match the syntax, and would probably result in a lot of cleanup. Thoughts?
I like that following your suggestion, a Var no longer needs to know that it's part of a Def/Lam.
But, it seems odd that Var can have a type itself, and have a type in the Def/Lam. Would type_propagation update the type in the Var, from the type in the containing Lam/Def ? (I suppose this is a bit like how typepropagation would have to set the `typefield of the Lam by reading the
arg_type` ?)
However, that may be a poor line of reasoning, as it seems to lead to Lam containing (arg: str, arg_type: Type, body: Expr), and I'm not sure whether that's just odd, or indeed accurate.
Or, since the decl
only really seems to affect equality (decl != non-decl) and printing, can we remove the decl
from Var, have Lam use the type_
in its arg, and then just use a different printing routine?
Or, since the
decl
only really seems to affect equality (decl != non-decl) and printing, can we remove thedecl
from Var, have Lam use thetype_
in its arg, and then just use a different printing routine?
That sounds good to me; I think it's the closest match for how our other AST implementations (Haskell and C++) handle this.
So do we want to drop this in favour of removing decl
altogether? @awf ?
Yes, let's drop decl. Thanks!
This continues in the theme of #827.
Let
vars never havedecl
set - the current codebase is 100% consistent on that front. So, this PR adds an assertion to enforce this (i.e. make sure we stay consistent in the future!). The assert also provides some documentation.There is a counterargument that we do not generally check vars elsewhere aren't
decl
, so why should we do so here? But I think we should so that we make clear thatdecl
does not mean "binding occurrence".A further extension might be to assert that
decl
is set for Def args, not done in this PR.