[Haskell-cafe] How to define an operation in terms of itself (but of different type)?

Roman Cheplyaka roma at ro-che.info
Sat Jan 24 10:44:08 EST 2009

* Olex P <hoknamahn at gmail.com> [2009-01-24 15:35:22+0000]
> But you know it doesn't make too much sense because I also have to define
> addition Scalar + Vector (that means construct vector from scalar and add a
> vector), Vector + Scalar and so on. And as we are not able to overload
> operations in C++ like way we have to create several different operations
> even if their meaning is pretty close. Probably it's possible with ad hoc
> overloading but I don't know is it good idea.

Consider defining functions with meaningful names (like
scalarPlusVector), you then can use them as infix operators:

    5 `scalarPlusVector` Vector 1 2 3 

Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain

More information about the Haskell-Cafe mailing list