Sunday, May 04, 2008

Type-getter

Given a complicated tuple type ([A],((B,C),[(D,E)],(F,(G,H),[J])) have the compiler automatically synthesize a "getter" funtion that extracts a sub-tuple matching a given (possibly polymorphic) type, for example, query "(B,C), or query "F", or query "(x,y,[z])" which matches (F,(G,H),[J]). This makes the program not have to be changed very much if the "schema" changes, say, to add on to the tuple type.

This could be interestingly abused by having a global variable "preludeFunctions" consisting of the type-unique prelude functions in a giant tuple, and querying into that, e.g., query "(a -> b) -> [a] -> [b]" gets you "map".

No comments :