[Haskell-cafe] How to define an operation in terms of itself (but
of different type)?
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Sat Jan 24 01:24:33 EST 2009
On 2009 Jan 23, at 17:58, Olex P wrote:
> class Vector v where
> (^+^) :: v -> v -> v
>
> class Matrix m where
> (^+^) :: m -> m -> m
You can't reuse the same operator in different classes. Vector
"owns" (^+^), so Matrix can't use it itself. You could say
> instance Matrix m => Vector m where
> (^+^) = ...
allowing Matrix to "inherit" Vector's operator (or turn it around the
other way, make it Matrix then make Vector a Matrix), but that's only
linguistically possible, not necessarily mathematically sane.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090124/2dfb42c2/attachment.htm
More information about the Haskell-Cafe
mailing list