On Feb 13, 2006, at 2:26 PM, [EMAIL PROTECTED] wrote:
[snip error message] I don't understand how m1 * m2 can match the scalar multiplication instances. For instance, the scalar * matrix instance has signature: To be fair, doing better than this (in general) seems pretty difficult. The typechecker sometimes needs to have more information than it can currently gather. I think the following extension proposal might address this problem (if its ever implemented...) As of now, the typechecker can't be absolutely certain that 'Matrix' isn't (and will never be) an instance of 'Num'. Just because you haven't make it a member of 'Num' doesn't mean someone else couldn't! For it to do what you want, the typechecker needs to be able to prove that, given any legal collection of instances, the instance declarations in question will not overlap. It can't to that. As to workarounds... that becomes more difficult. Essentially you need to replace the bare type variable 'a' in your instance declarations with something that can guide the typechecker to select the 'correct' instance. Two options come to mind: 1) create a 'newtype' for scalars. Now you have to wrap and unwrap your scalars, which is a bit of a pain, but it is a fully general solution. Judicious use of newtype deriving may eliminate some of this pain. 2) Create separate 'Multiply' instances for each type of scalar you want to use. Eliminates the ugly wrapping/unwrapping, but limits the types of scalars you can use. Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG |
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe