This is just a comment really, rather than a question...
I was surprised that there's no type inference when using List.map, for the following gives a compilation Err.
class Example { Void main() { types := #main.params.map |param->Type| { param.type } types.first.qname // Err --> Unknown slot 'sys::Obj.qname' } }
The generics system is not capable of typing that expression at compile type. So map always returns a generic list at compile time. However, the runtime does look at the type of the mapping function to allocate the correct list type. Consider:
Type[] types := #main.params.map |param->Type| { param.type } echo(types.typeof) echo(types.first.qname)
The runtime type of types is Type[] which actually means on the JVM that the backing store is a Type[] array.
types
Type[]
Login or Signup to reply.
SlimerDude Sat 7 Dec 2013
This is just a comment really, rather than a question...
I was surprised that there's no type inference when using List.map, for the following gives a compilation Err.
brian Mon 9 Dec 2013
The generics system is not capable of typing that expression at compile type. So map always returns a generic list at compile time. However, the runtime does look at the type of the mapping function to allocate the correct list type. Consider:
The runtime type of
types
isType[]
which actually means on the JVM that the backing store is aType[]
array.