le-michael / ElmJrMetalEdition

2 stars 0 forks source link

EINodes should be type annotated #110

Open Necried opened 3 years ago

Necried commented 3 years ago

While the Hindley-Milner type system does perform type erasure at runtime, it makes sense for us to keep track of EINode types as they're necessary for the projectional editor. With that in mind, there are two approaches to do this:

  1. Annotate each node with their type
  2. Have a global dictionary associating each node to their type

In the type-inferencer, I currently use a modified version of approach (2), where I only keep track of declarations. However, this has to be extended if we want to do it for all nodes.

The main issue here is how we deal with variable scope - there could be multiple declarations of the same variable name. Also, most of our other nodes are "anonymous", as there isn't really a declaration associated to each individual node.

Taggin @WyattWismer and @thomas-armena as this is relevant for the projectional editor and potential AST modification

Necried commented 3 years ago

I would prefer if we use approach (2) as its easier to query type information of identifiers by just looking up information in the dictionary. For example, if a user has code in their editor like this:

if x < 3 then f x else f (f x)

it would be much simpler to look up the type of f and x from a dictionary.

In terms of scoping issues, Issue #93 talks about a method to assign a unique identifier for each logical variable that we could use in this context.

In terms of storing type information of non-declaration nodes, if we can hash our nodes then we could have a dictionary associating the hash of a node to its type. Otherwise, I don't think we need types of non-declaration nodes in a global context and we can just default to Approach (1) for this.

WyattWismer commented 3 years ago

What is the motivation to hash the nodes rather than to just map the pointer to the type?

Necried commented 3 years ago

Probably not useful outside of providing unique identifiers to individual nodes