Interfaces - the Golden Path of Haskell?

Wvv vitea3v at rambler.ru
Mon Jul 8 21:29:33 CEST 2013


And this is only tip of the iceberg.

Now we have discussion about

(Monad m) vs. (Functor m => Monad m).

With class interfaces it is not an option: we have them both(!!!)


{{{

class Monad m where ...

class Functor m => Applicative m => Monad m where ..

}}}


Let's see how it could work:


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
}}}


Wvv




--
View this message in context: http://haskell.1045720.n5.nabble.com/Interfaces-the-Golden-Path-of-Haskell-tp5732208p5732572.html
Sent from the Haskell - Haskell-prime mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-prime/attachments/20130708/52cd7739/attachment.htm>


More information about the Haskell-prime mailing list