Opaque result types

I would like those too, but I think the main point I am trying to get across is that rather than having syntax which always infers the internal type:

keyword TypeAsSeen

We should have:

Type keyword TypeAsSeen

and if we really want to be able to infer the internal type, we would use:

_  keyword TypeAsSeen

I have proposed as for the keyword so we don't have to burn a new one (and because it is short):

[Int] as C:Collection where C.Element == Int

or using sugar as others proposed:

[Int] as Collection<Element == Int>

or if you want to infer the type:

_ as Collection<Element == Int>

I know it is an extra character (+ space) from your proposal, but this has a lot of advantages:

  • We can explicitly define the internal type when needed/desired
  • The same syntax can be used for opaque type aliases (i.e. you only have to learn 1 syntax)
  • The same syntax can be used for properties (i.e. you only have to learn 1 syntax)
  • The same syntax can be used for etc...
  • All of the information about the type can be found in one spot (you don't have to search the func)
  • It is more concrete to explain to people
  • It doesn't use _.Element which I find a very troubling syntax
1 Like