Hindley-Milner - conditional Substitutions?

68 Views Asked by At

I have been trying to build a type system with the Hindley-Milner Algorithm and ran into the following challenge and was curious if there are any resources or papers out there I can take a look at.

Suppose I have a programming language that has some form of property accessor (javascript-like) that works for both arrays and objects, s.t. the property within the brackets for an array needs to be a number and the property within the brackets for an object needs to be a string.

For example

const arr = [0, 1, 2]
arr[0]

const obj = { hello: "World" }
obj["hello"]

Suppose we want to use hindley-milner on the following code snippet

A[B]

Then if later we realized that B is a number, then we instantly deduce that A is an array. Similarly, if we deduce that A is an object, then B is instantly a number.

Are there any papers or type systems out there that have this sort of conditional substitution concept?

0

There are 0 best solutions below