[nem-en] Clarification on type-inference rules.
Gerard Murphy
g.j.murphy at sageserpent.com
Sat Nov 12 15:46:31 CET 2005
Michal,
Five minutes after sending that last message I've realised why my previous
suggestion won't work...
> If this is the case, couldn't you simply put in an internal placeholder
> type
> for a local polymorphic type when compilation of the enclosing scope is
> complete?
>
> Of course, if you had a subsequent mutative operation that would add an
> element to a polymorphically-typed array value, I presume that the process
> of type unification would pick up the type of the element and therefore
> bind
> the type variable of the array type: so you would only need to use a
> placeholder for the one specific case where the array type still contains
> an
> unbound type variable in purely functional code.
>
> I have a feeling that I've missed something terribly obvious here - feel
> free to refer me elsewhere if this is getting painful. :-)
>
... you would have to support upcasting a polymorphically typed array up to
System.Object or System.Array.
This then begs the question as to what the run-time type of the array should
be if you were downcasting - and how you would add an element to it!
Also, the analogy between 'array[]' and '[]' isn't exact - the former allows
mutative operations that would have to know the element type, whereas the
latter is immutable.
Doh: I think I'll go back to working through the exercises... :-)
Cheers,
Gerard
More information about the devel-en
mailing list