Hi,
I am trying to define a commutative operator : (%+) :: a -> b -> c (%+) :: b -> a -> c instead of defining a class and instantiating twice
every time, I am trying to do the following:
class Commutative a b c where (%+) :: a -> b -> c class Operation a b c | a b -> c
where
(%+%) :: a -> b -> c instance (Operation a b c) => Commutative a b c
where
(%+) = (%+%) instance (Operation b a c) => Commutative a b c
where
(%+) = flip (%+%) --
instance Operation Int (Maybe Int) Int
where
i %+% (Just s) = i + s ---
With hugs -98 +mo ((2::Int) %+ (Just (2::Int)))::Int gives 4 But (2::Int) %+ (Just (2::Int)) is of type Commutative Int (Maybe Int) a => a. So is (Just (2::Int)) %+ (2::Int) Is the dependency in Operation class not
sufficient. Any work around?
Which flags to be set for Ghc to accept this code.
I tried -fallow-overlapping-instances
and
-fallow-undecidable-instances. Thanks,
S |