Dear All, I have this following simplified problem. Please help. type Formula a b = a -> b type Env = (Integer,Char) fun :: Formula Integer Integer fun n = n+1 sun :: Formula Char Integer sun c = toInteger.ord c I want to be able to write (sun + fun) (2,'a') (fun + sun) (2,'a') both of which should be equal to (sun 'a' + fun 2) So I did this: lift2 :: (a -> b -> c) -> Formula d a -> Formula e b -> Formula Env c lift2 f a1 a2 = \env -> f ( (lift a1) n ) ( (lift a2) n ) -- Here hugs gives error class Lift a where lift :: Formula a b -> Formula Env b instance Lift Char where lift f = \(i,c) -> f c instance Lift Integer where lift f =\(i,c) -> f i With this, hugs (with extensions enabled) gives following error: Cannot justify constraints in explicitly typed binding ***Expression : lift2 ***Type : (a -> b -> c) -> Formula d a -> Formula e b -> Formula Env c ***Given Constraint: () ***Constraints : (Lift d, Lift e) Any help is very much appreciated. Thanks, Saswat
Tis the season for type class overloading fun... On 2001-02-16T21:45:32+0800, Saswat Anand wrote:
lift2 :: (a -> b -> c) -> Formula d a -> Formula e b -> Formula Env c
This type is too general. You need to specify a context that requires both d and e to satisfy Lift: lift2 :: (Lift d, Lift e) => (a -> b -> c) -> Formula d a -> Formula e b -> Formula Env c -- Edit this signature at http://rodimus.digitas.harvard.edu/cgi-bin/ken/sig "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" - Ernst Jan Plugge
Thanks a lot. It works fine. Could you help me with this. With the following defintions, I want to be able to write (high \+ 4) (3.4,2) and (4 \+ high) (3.4,2) which both should be equal to 4+ (high 2) = 6. But hugs gives following error during run time: ERROR: Unresolved overloading *** Type : Lift a => Integer *** Expression : (high \+ 4) (1,1) type Formula a b = a -> b (\+) :: (Lift a,Lift c,Num b)=>Formula a b -> Formula c b -> Formula Env b p \+ q = \env -> (lift p) env + (lift q) env type Env = (Double,Integer) class Lift a where lift :: Formula a b -> Formula Env b instance Lift Double where lift f (c,i) = f c instance Lift Integer where lift f (c,i) = f i instance Lift Env where lift = id high :: Formula Integer Integer high n = n+1 low :: Formula Double Integer low = round instance Eq (Formula a b) where (==) = error "<< error >>" instance Show (Formula a b) where showsPrec n a1 = error "<< Formula >>" instance (Num b) => Num (Formula a b) where -- I tried instance (Lift a, Num b) =>...... does not work fromInteger x = \a -> fromInteger x Thanks, Saswat ----- Original Message ----- From: Ken Shan <ken@digitas.harvard.edu> To: Saswat Anand <iscp9157@nus.edu.sg> Cc: <haskell@haskell.org> Sent: Friday, February 16, 2001 12:17 PM Subject: Re: Lifting to the limit
Tis the season for type class overloading fun...
On 2001-02-16T21:45:32+0800, Saswat Anand wrote:
lift2 :: (a -> b -> c) -> Formula d a -> Formula e b -> Formula Env c
This type is too general. You need to specify a context that requires both d and e to satisfy Lift:
lift2 :: (Lift d, Lift e) => (a -> b -> c) -> Formula d a -> Formula e b -> Formula Env c
-- Edit this signature at http://rodimus.digitas.harvard.edu/cgi-bin/ken/sig "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" - Ernst Jan Plugge
participants (2)
-
Ken Shan -
Saswat Anand