Re: [GHC] #8021: Multiple constraint classes - the alternative to superclass

#8021: Multiple constraint classes - the alternative to superclass -------------------------------------+------------------------------------ Reporter: wvv | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by wvv): * difficulty: => Unknown Comment: It's also useful other cases. We have {{{ class Num a where (+), (*) :: a -> a -> a (-) :: a -> a -> a negate :: a -> a fromInteger :: Integer -> a }}} Let we also have {{{ class Additive a where plus :: a -> a -> a zero :: a class Additive a => AdditiveNegation a where minus :: a -> a -> a negation :: a -> a x `minus` y = x `plus` negation y class Multiplicative a where multiply :: a -> a -> a one :: a class FromInteger a where fromInteger' :: Integer -> a }}} Now we wish to unite both of them For example, we could also define next: {{{ class (Additive a, Additive a => AdditiveNegation a, Multiplicative a, FromInteger a) => Num a where (+) = plus (*) = multiply (-) = minus negate = negation fromInteger = fromInteger' class (Num a) => Additive a where plus = (+) zero :: a default zero :: () => Additive a => a default zero = zero class (Num a) => AdditiveNegation a where minus = (-) negation = negate class (Num a) => Multiplicative a where multiply = (*) one :: a default one :: () => Multiplicative a => a default one = one class (Num a) => FromInteger a where fromInteger' = fromInteger }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8021#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC