ta0kira / zeolite

Zeolite is a statically-typed, general-purpose programming language.
Apache License 2.0
18 stars 0 forks source link

Add minimal param inference. #69

Closed ta0kira closed 4 years ago

ta0kira commented 4 years ago

Possible syntax:

\ Type<_,String>$foo<_,_>(bar,baz)

The idea is to use place-holders for params that should be inferred, rather than leaving them out entirely like in Java and C++.

Tre process might work like this:

  1. Enumerate the place-holders.
  2. Perform substitution within the arg types as usual.
  3. Generalize type-checking to return param guesses.
  4. Merge guesses or just throw an error for ambiguities.
  5. Fill in place-holders.
  6. Process the function call as normal.

This process implies that something like foo<Baz<_>>(bar) might also be allowed.

ta0kira commented 4 years ago

Variance in context should also be collected, in case multiple matches are going to be merged.

ta0kira commented 4 years ago

Allowing Type<_>$foo(bar) or Type$foo<Baz<_>>(bar) might not be a good idea because it would require either allowing _ everywhere types are used, or adding extra checks for unresolved place-holders everywhere types are used.