3 ms·
MultiParameterTypeClasses are a fine feature! It's the ones like UndecidableInstances that you have to be careful about.
by ezyang 15y ago
MultiParameterTypeClasses are a fine feature! It's the ones like UndecidableInstances that you have to be careful about.
- awj 15y agoThey are, until someone makes a five parameter monster because "someday I'll want that genericity." To be honest, though, I just googled the extensions I could remember until I hit one that hinted at creating a situation where the compiler simply doesn't have enough information to compile your code. That said, yeah, UndecidableInstances look like a much better example. Especially when googling it turns up things like this: http://lukepalmer.wordpress.com/2008/04/08/stop-using-undecidable-instances/ http://lukepalmer.wordpress.com/2008/04/08/stop-using-undeci...
- nickik 15y agoIs MultiParameterTypeClasses something like multible dispatch from CLOS?
- pwpwp 15y agono
- awj 15y agoIn that both embody the concept of using the types of multiple arguments to determine which instance of a function gets called, yes. That's where the similarity ends, though. CLOS does this at runtime during method invocation, MPTC "dispatch" is determined at compile time. Multiple dispatch will generally have some overhead that MPTC won't, but it's more flexible in that the set of function implementations can be extended without recompiling. Also, due to limitations of type analysis or type expressivity, it's possible to write something that would work for the specific instances where you are using MPTC but can't be proven to work for all instances of the types involved. Then again this is almost always an issue with static typing. Wether the compiler is saving you from a bad decision or keeping you from doing your job is a matter of personal opinion.
- nickik 15y agoThanks very intresting. You might be intressted in this paper I read just a couple of days ago: "Extending Dylan’s type system for better type inference and error detection". (Dylan OO is simular to CLOS) A system like that helps to get the dispatch overhead down while still beeing able to extend it at runtime and you get alot of the typesafty. http://opendylan.org/documentation/publications.html http://opendylan.org/documentation/publications.html