I want to substitute a specific AST node into another, and this substituted node is specified by interactive user input.
In non-functional programming, you can use mutable data structure, and each AST node have a object reference, so when I need to reference to a specific node, I can use this reference.
But in functional programming, use IORef
is not recommended, so I need to generate id for each AST node, and I want this id to be stable, which means:
- when a node is not changed, the generated id will also not change.
- when a child node is changed, it's parent's id will not change.
And, to make it clear that it is an id instead of a hash value:
- for two different sub nodes, which are compared equal, but corresponding to different part of an expression, they should have different id.
So, what should I do to approach this?