[Haskell-cafe] instance Monad m => Functor m
Hans Aberg
haberg at math.su.se
Wed Apr 9 10:06:23 EDT 2008
On 9 Apr 2008, at 15:23, Henning Thielemann wrote:
>> I don't know if it is possible to extend the syntax this way, but
>> it would be closer to math usage. And one would avoid duplicate
>> definitions just to indicate different operator names, like:
>> class AdditiveMonoid a where
>> o :: a
>> (+) :: a -> a -> a
>> as it could be create using
>> class Monoid (a; o, (+))
>
> I also recognized that problem in the past, but didn't know how to
> solve it. In Haskell 98, methods are resolved using the types of
> the operands. How would the compiler find out which implementation
> of (+) to choose for an expression like x+y using your approach?
Different names result in different operator hierarchies. So a class
like
class Monoid (a; unit, mult) where
unit :: a
mult :: a -> a -> a
must have an instantiation that specifies the names of the operators.
In particular, one will need a
class (Monoid (a; 0; (+)), ...) => Num a ...
if (+) should be used as Monoid.(+) together with Num.(+).
Or give an example you think may cause problems, and I will give it a
try.
Hans
More information about the Haskell-Cafe
mailing list