True. Thanks. - Lauri
On Sat, Mar 21, 2009 at 1:05 AM, Lennart Augustsson <[email protected]> wrote: > That's a horrible definition of fromRational. Use > fromRational = P.fromRational. > > On Fri, Mar 20, 2009 at 9:09 PM, Lauri Oksanen <[email protected]> wrote: >> Thanks for answers. Here is some working code if somebody plays later >> with similar things. >> >> {-# OPTIONS >> -XNoImplicitPrelude >> -XFunctionalDependencies >> -XMultiParamTypeClasses >> -XFlexibleInstances >> #-} >> module Test ( >> Integer >> , Double >> , fromInteger >> , fromRational >> , (+) >> ) where >> import Prelude (Integer, Double) >> import qualified Prelude as P >> import qualified GHC.Real >> >> fromInteger :: Integer -> Integer >> fromInteger = P.id >> >> fromRational :: P.Rational -> Double >> fromRational (n GHC.Real.:% d) = let >> n' = P.fromInteger n :: Double >> d' = P.fromInteger d :: Double >> in n' P./ d' >> >> >> -- Prelude types --------- >> >> instance Semigroup Integer where plus = (P.+) >> instance Semigroup Double where plus = (P.+) >> instance Subset Integer Double where embed = P.fromInteger >> >> >> -- Class hierarchy --------- >> >> class Plus a b c | a b -> c where >> (+) :: a -> b -> c >> >> class Semigroup a where >> plus :: a -> a -> a >> >> class Subset a b where >> embed :: a -> b >> >> instance (Semigroup a) => (Plus a a a) where (+) = plus >> >> >> -- Coercion rules --------- >> >> instance Plus Double Integer Double where >> x + j = x + (embed j :: Double) >> instance Plus Integer Double Double where >> j + x = (embed j :: Double) + x >> >> >> Ps. I'm very interested in hearing, if somebody has ideas, how to >> generalize the coercion rules to something like >> >> instance (Semigroup a) => (Subset b a) => (Plus a b a) where >> x + j = x + (embed j) >> >> >> - Lauri >> >> On Fri, Mar 20, 2009 at 3:58 PM, Lennart Augustsson >> <[email protected]> wrote: >>> I think your best bet is -fno-implicit-prelude, and defining >>> fromInteger = id :: Integer->Integer. >>> >> _______________________________________________ >> Haskell-Cafe mailing list >> [email protected] >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
