atom feed35 messages in org.haskell.haskell[Haskell] PROPOSAL: class aliases
FromSent OnAttachments
John MeachamOct 12, 2005 7:41 pm 
Philippa CowderoyOct 12, 2005 7:55 pm 
John MeachamOct 12, 2005 8:16 pm 
Wolfgang JeltschOct 13, 2005 5:48 am 
John MeachamOct 13, 2005 6:03 am 
Malcolm WallaceOct 13, 2005 6:15 am 
Andres LoehOct 13, 2005 6:23 am 
Malcolm WallaceOct 13, 2005 6:29 am 
John MeachamOct 13, 2005 6:37 am 
John MeachamOct 13, 2005 6:39 am 
Simon Peyton-JonesOct 13, 2005 7:02 am 
Benjamin FranksenOct 13, 2005 7:26 am 
Benjamin FranksenOct 13, 2005 7:33 am 
S.M.KahrsOct 13, 2005 7:37 am 
John MeachamOct 13, 2005 8:32 am 
Simon Peyton-JonesOct 13, 2005 9:23 am 
Udo StenzelOct 13, 2005 9:46 am 
Jan-Willem MaessenOct 13, 2005 9:58 am 
Paul GovereauOct 13, 2005 1:21 pm 
Jacques CaretteOct 13, 2005 1:52 pm 
John MeachamOct 13, 2005 4:45 pm 
John MeachamOct 13, 2005 6:13 pm 
John MeachamOct 13, 2005 6:21 pm 
David MenendezOct 13, 2005 6:49 pm 
John MeachamOct 13, 2005 8:33 pm 
aj...@spamcop.netOct 13, 2005 11:25 pm 
Ashley YakeleyOct 14, 2005 6:20 am 
Ashley YakeleyOct 14, 2005 6:31 am 
Wolfgang JeltschOct 14, 2005 9:46 am 
Wolfgang JeltschOct 14, 2005 11:44 am 
Wolfgang JeltschOct 14, 2005 11:47 am 
Remi TurkOct 14, 2005 2:05 pm 
Udo StenzelOct 15, 2005 6:15 am 
Ross PatersonOct 27, 2005 6:58 am 
Wolfgang JeltschOct 28, 2005 7:05 am 
Subject:[Haskell] PROPOSAL: class aliases
From:Paul Govereau (gove@eecs.harvard.edu)
Date:Oct 13, 2005 1:21:30 pm
List:org.haskell.haskell

On Oct 12, John Meacham wrote:

class Num a where (+), (*) :: a -> a -> a (-) :: a -> a -> a negate :: a -> a fromInteger :: Integer -> a

ideally we would want to split it up like so (but with more mathematically precise names):

class Additive a where (+) :: a -> a -> a zero :: a

class Additive a => AdditiveNegation where (-) :: a -> a -> a negate :: a -> a x - y = x + negate y

class Multiplicative a where (*) :: a -> a -> a one :: a

class FromInteger a where fromInteger :: Integer -> a

class alias (Addititive a, AdditiveNegation a, Multiplicative a, FromInteger a) => Num a where one = fromInteger 1 zero = fromInteger 0 negate x = zero - x

This class alias isn't 100% backwards compatible, because the original Num class doesn't have a zero method. For instance, if I had written this function in my program:

zero :: Num a => a zero = fromInteger 0

Then, after swapping in the new alias, Num, the compiler would probably complain that I have multiple definitions for zero.

Perhaps there could be a mechanism for hiding class methods as well? e.g.

class alias (Addititive a without zero, -- remove zero AdditiveNegation a, Multiplicative a, FromInteger a) => Num a where ...

I am not sure this could still be done with a source-to-source translation, but perhaps it is worth considering. Of course, if we allow union and subtraction, then why not addition, intersection, complement (ok, maybe not complement).

Paul