haskell-cafe@haskell.org
[Top] [All Lists]

Re: [Haskell-cafe] How to define an operation in terms of itself (but of

Subject: Re: [Haskell-cafe] How to define an operation in terms of itself (but of different type)?
From: Roman Cheplyaka
Date: Sat, 24 Jan 2009 17:44:08 +0200
* Olex P <hoknamahn@xxxxxxxxx> [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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>