Re: How overload operator in Haskell?

2003-11-05 Thread Ketil Z. Malde
Andrew J Bromage [EMAIL PROTECTED] writes: class Plus a b c | a b - c where (+) :: a - b - c class Mult a b c | a b - c where (*) :: a - b - c This kind of approach was discussed a while ago, and has a bunch of things to recommend it. Is the functional

Re: How overload operator in Haskell?

2003-07-12 Thread Andrew J Bromage
G'day all. On Fri, Jul 11, 2003 at 04:28:19PM -0400, Dylan Thurston wrote: Don't be silly [...] Never! Cheers, Andrew Bromage ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

Re: How overload operator in Haskell?

2003-07-12 Thread Jon Fairbairn
On 2003-07-12 at 20:20+1000 Andrew J Bromage wrote: G'day all. On Fri, Jul 11, 2003 at 04:28:19PM -0400, Dylan Thurston wrote: Don't be silly [...] Never! Or only sometimes. I'm surprised that no-one has yet answered the question How overload operator in Haskell? with Overload operator

Re: How overload operator in Haskell?

2003-07-12 Thread Liu Junfeng
answered the question How overload operator in Haskell? with Overload operator in Haskell fine. (cf Cary Grant) I am also surprised at this, it can be done by C++ . -- J? Fairbairn [EMAIL PROTECTED] 31 Chalmers Road [EMAIL

Re: How overload operator in Haskell?

2003-07-12 Thread Ganesh Sittampalam
On Thu, 10 Jul 2003 10:58:51 +1000, Andrew J Bromage [EMAIL PROTECTED] wrote: This suggests that wrapping each standard mathemtaical function/operator in its own typeclass would have literally no run-time performance penalty: class Plus a b c | a b - c where (+) :: a - b - c

Re: How overload operator in Haskell?

2003-07-12 Thread Dylan Thurston
On Fri, Jul 11, 2003 at 05:38:18PM +1000, Andrew J Bromage wrote: G'day all. On Thu, Jul 10, 2003 at 11:16:56PM -0700, Ashley Yakeley wrote: As written, this is _not_ a good idea. Trust me, you end up having to put type annotations everywhere. Even (3 + 4 :: Integer) is ambiguous,

Re: How overload operator in Haskell?

2003-07-11 Thread Ashley Yakeley
In article [EMAIL PROTECTED], Glynn Clements [EMAIL PROTECTED] wrote: instance Num Vector where Except that class instances have to be algebraic datatypes (data) or renamed datatypes (newtype), but not type synonyms (type). That's not true, is it? I mean as long as there isn't already

Re: How overload operator in Haskell?

2003-07-11 Thread Ashley Yakeley
In article [EMAIL PROTECTED], Andrew J Bromage [EMAIL PROTECTED] wrote: This suggests that wrapping each standard mathemtaical function/operator in its own typeclass would have literally no run-time performance penalty: class Plus a b c | a b - c where (+) :: a - b - c

Re: How overload operator in Haskell?

2003-07-11 Thread Martin Sjögren
fre 2003-07-11 klockan 08.07 skrev Ashley Yakeley: In article [EMAIL PROTECTED], Glynn Clements [EMAIL PROTECTED] wrote: instance Num Vector where Except that class instances have to be algebraic datatypes (data) or renamed datatypes (newtype), but not type synonyms (type).

Re: How overload operator in Haskell?

2003-07-11 Thread Andrew J Bromage
G'day all. On Thu, Jul 10, 2003 at 11:16:56PM -0700, Ashley Yakeley wrote: As written, this is _not_ a good idea. Trust me, you end up having to put type annotations everywhere. Even (3 + 4 :: Integer) is ambiguous, you have to write (3 :: Integer) + (4 :: Integer). But that's what

How overload operator in Haskell?

2003-07-09 Thread Liu Junfeng
I've learned haskell months, but I still can't understand the type system very well. I can only write: --- type Vector = [Double] vadd,vsub :: Vector-Vector-Vector v1 `vadd` v2 = zipWith (+) v1 v2 v1 `vsub` v2 = zipWith (-) v1 v2 svmul :: Double-Vector-Vector s

RE: How overload operator in Haskell?

2003-07-09 Thread Hal Daume
- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Liu Junfeng Sent: Wednesday, July 09, 2003 7:25 AM To: [EMAIL PROTECTED] Subject: How overload operator in Haskell? I've learned haskell months, but I still can't understand the type system very well. I can only write

Re: How overload operator in Haskell?

2003-07-09 Thread Jerzy Karczmarczuk
Hal Daume answers a question on how to define nice, infix ops acting on vectors: What you want to do is make your Vector an instance of the Num(eric) type class. For instance: instance Num Vector where (+) v1 v2 = zipWith (+) v1 v2 (-) v1 v2 = zipWith (-) v1 v2 negate v1 = map negate v1

RE: How overload operator in Haskell?

2003-07-09 Thread Hal Daume
PROTECTED] Subject: Re: How overload operator in Haskell? While this is a possible solution, I would shout loudly: Arrest this man, he is disrespectful wrt math!. Actually, this shows once more that the Num class and its relatives is a horror... Signum in this context has no sense. The multiplication

Re: How overload operator in Haskell?

2003-07-09 Thread Wolfgang Jeltsch
On Wednesday, 2003-07-09, 17:11, CEST, Hal Daume wrote: What you want to do is make your Vector an instance of the Num(eric) type class. It would be better to define one's own operators instead of using + and - because Vector has no meaningful instance of Num (as Jerzy Karczmarczuk already

Re: How overload operator in Haskell?

2003-07-09 Thread Andrew J Bromage
G'day all. On Wed, Jul 09, 2003 at 05:25:20PM +0200, Jerzy Karczmarczuk wrote: While this is a possible solution, I would shout loudly: Arrest this man, he is disrespectful wrt math!. Actually, this shows once more that the Num class and its relatives is a horror... Yup. I recently

RE: How overload operator in Haskell?

2003-07-09 Thread Glynn Clements
Hal Daume wrote: What you want to do is make your Vector an instance of the Num(eric) type class. For instance: instance Num Vector where Except that class instances have to be algebraic datatypes (data) or renamed datatypes (newtype), but not type synonyms (type). -- Glynn Clements

How overload operator in Haskell?

2003-07-09 Thread Liu Junfeng
I've learned haskell months, but I still can't understand the type system very well. I can only write: --- type Vector = [Double] vadd,vsub :: Vector-Vector-Vector v1 `vadd` v2 = zipWith (+) v1 v2 v1 `vsub` v2 = zipWith (-) v1 v2 svmul :: Double-Vector-Vector s