Thanks a lot. It works great with Hugs. But it has a small problem. I also want to be able to write 4 \+ fc :: CF fc \+ 4 :: CF ic \+ 4 :: IF 4 \+ fc \+ ic :: CIF Well for that I did this, instance (Rational a) => Plus a CF CF where --to support 4.0 \+ fc f \+ g = \c -> (realToFrac f) \+ (g c) I did not do : instance Plus Float CF CF where .. so that I don't have to write (4::Float) \+ fc. But it complains because, it violates functional dependency a b -> c. Is there any other way to avoid writing (4::Float) in this case. Well I tried this: (\+) :: (Lift a c, Lift b c) => a -> b -> (c -> Float) f \+ g = \x -> (lift f) x + (lift f) x class Lift a b where lift :: a -> (b -> Float) instance Lift CF Char where lift = id instance Lift CF (Char,Integer) where lift f = \(c,i) -> f c instance Lift IF Integer where lift = id instance Lift IF (Char,Integer) where lift f = \(c,i) -> f i instance Lift CIF (Char,Integer) where lift = id But it does not take following: x :: CF x = cf \+ cf \+ cf Cannot justify constraints in explicitly typed binding *****Expresssion : x *****Type : CF *****Given Context : () *****Constraints : (Lift (a -> Float) Char, Lift (Char -> FLoat) a) Thanks, Saswat
Wed, 7 Mar 2001 01:00:05 -0800, Saswat Anand <iscp9157@nus.edu.sg> pisze:
But it has a small problem. I also want to be able to write
4 \+ fc :: CF fc \+ 4 :: CF ic \+ 4 :: IF 4 \+ fc \+ ic :: CIF
You can have more fundeps which allow to deduce a type of an argument from the other argument and the result: | a b -> c, a c -> b, b c -> a and make CF and IF instances of Integral (define fromIntegral for them). -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
participants (2)
-
qrczak@knm.org.pl -
Saswat Anand