The problem is representing the value.
Traditional higher-order polymorphism languages ββhave made it easier to choose that all values ββare presented in a uniform way, usually in one word, with some smart tags to indicate whether it is a direct integer or a pointer to a structure with a common representation (some tags, etc. ) for all other values, such as data structures or functions.
If you have this assumption, you can compile each polymorphic function once and use it for all arguments of all types: they have a view accepted by the compiled function.
Now say that you are throwing types with other views, for example. a few continuous words on the stack. You can no longer use your one compiled function because it expects one word, so the calling convention is wrong. Something's broken.
This can be fixed in various ways, for example:
transmit along with the values ββsome information about their representation (you could consider this information a kind of information of type "type", but in fact you do not need complete information about the type, just some information about the representation); this is what the TILT compiler learned, for example
try to compile several specialized versions of your polymorphic function for each possible representation, and then decide (also based on the sort tag or some statically available information) which version to call. This may be wise with an optimization scheme for the entire program, such as MLton's. This is more or less a choice (rather, a choice) of choosing the first idea.
restrict polymorphisms using a species system to distinguish between "types of one word" and "types of tuples." Instead of the usual "for all types" polymorphism, you will have a relativized version of "for all types of this kind ...". This allows the programmer to statically pose the question of which function can accept argument types ("ow, this function is polymorphic, so I have to specify my value type here") instead of hoping the compiler gets the right permissions, but it also does the type system is heavier: you do not maintain the illusion of homogeneity.
In short, a combined (some form) polymorphism with rich options for presenting data is possible, but much more complicated than in the case of a uniform representation.
gasche
source share