|
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 |
- Can Class do this? Saswat Anand
- Re: Can Class do this? Marcin 'Qrczak' Kowalczyk
- Re: Can Class do this? Saswat Anand
- Re: Can Class do this? Marcin 'Qrczak' Kowalczyk
