Re: [Haskell] type class does not compile

2004-07-13 Thread Graham Klyne
At 19:24 12/07/04 -0500, [EMAIL PROTECTED] wrote:
Hi,
please bear with me if my question turns out to be a stupid mistake. It has
taken me hours to figure this out.
class Rule r u u' m where
  apply :: r - u - m u'
data And = And
data Bin a b o = Bin a b o
instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) = Rule (Bin r1 r2
And) u u'' m where
  apply (Bin r1 r2 _) u = apply r1 u = apply r2
Ghc complains about Could not deduce (Rule r1 u u'1 m, Rule r2 u'1 u''
m), but it is obviously same as the constraint I gave in the instance
declaration.
What am I doing wrong here?
There's no information in the instance type for the compiler to figure out 
what u' (in the constraint expressions) might be.  (See other responses.)

...
I would question whether or not you really should be using a type class 
here -- that depends on your application, but I've done some work involving 
simple inference rules and found that a polymorphic algebraic datatype 
(with function-valued members) served my purposes better than a type class.

#g
--
Thank you very much!
This message is intended only for the addressee and may contain information
that is confidential or privileged. Unauthorized use is strictly prohibited
and may be unlawful. If you are not the intended recipient, or the person
responsible for delivering to the intended recipient, you should not read,
copy, disclose or otherwise use this message, except for the purpose of
delivery to the addressee. If you have received this email in error, please
delete and advise us immediately.
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] type class does not compile

2004-07-12 Thread Ben . Yu
Hi,
please bear with me if my question turns out to be a stupid mistake. It has
taken me hours to figure this out.

class Rule r u u' m where
  apply :: r - u - m u'

data And = And

data Bin a b o = Bin a b o

instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) = Rule (Bin r1 r2
And) u u'' m where
  apply (Bin r1 r2 _) u = apply r1 u = apply r2

Ghc complains about Could not deduce (Rule r1 u u'1 m, Rule r2 u'1 u''
m), but it is obviously same as the constraint I gave in the instance
declaration.

What am I doing wrong here?

Thank you very much!


This message is intended only for the addressee and may contain information
that is confidential or privileged. Unauthorized use is strictly prohibited
and may be unlawful. If you are not the intended recipient, or the person
responsible for delivering to the intended recipient, you should not read,
copy, disclose or otherwise use this message, except for the purpose of
delivery to the addressee. If you have received this email in error, please
delete and advise us immediately.

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] type class does not compile

2004-07-12 Thread Martin Sulzmann

Try class Rule r u u' m | r u - u'

Martin


  Hi,
  please bear with me if my question turns out to be a stupid mistake. It has
  taken me hours to figure this out.
  
  class Rule r u u' m where
apply :: r - u - m u'
  
  data And = And
  
  data Bin a b o = Bin a b o
  
  instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) = Rule (Bin r1 r2
  And) u u'' m where
apply (Bin r1 r2 _) u = apply r1 u = apply r2
  
  Ghc complains about Could not deduce (Rule r1 u u'1 m, Rule r2 u'1 u''
  m), but it is obviously same as the constraint I gave in the instance
  declaration.
  
  What am I doing wrong here?
  
  Thank you very much!
  
  
  This message is intended only for the addressee and may contain information
  that is confidential or privileged. Unauthorized use is strictly prohibited
  and may be unlawful. If you are not the intended recipient, or the person
  responsible for delivering to the intended recipient, you should not read,
  copy, disclose or otherwise use this message, except for the purpose of
  delivery to the addressee. If you have received this email in error, please
  delete and advise us immediately.
  
  ___
  Haskell mailing list
  [EMAIL PROTECTED]
  http://www.haskell.org/mailman/listinfo/haskell
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] type class does not compile

2004-07-12 Thread Martin Sulzmann

Another solution would be to use lexically scoped type variables:

instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) = Rule (Bin r1 r2 And) u u'' m 
where
  apply (Bin r1 r2 _) u = ((apply r1 u)::m u') = apply r2

Martin


  Hi,
  please bear with me if my question turns out to be a stupid mistake. It has
  taken me hours to figure this out.
  
  class Rule r u u' m where
apply :: r - u - m u'
  
  data And = And
  
  data Bin a b o = Bin a b o
  
  instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) = Rule (Bin r1 r2
  And) u u'' m where
apply (Bin r1 r2 _) u = apply r1 u = apply r2
  
  Ghc complains about Could not deduce (Rule r1 u u'1 m, Rule r2 u'1 u''
  m), but it is obviously same as the constraint I gave in the instance
  declaration.
  
  What am I doing wrong here?
  
  Thank you very much!
  
  
  This message is intended only for the addressee and may contain information
  that is confidential or privileged. Unauthorized use is strictly prohibited
  and may be unlawful. If you are not the intended recipient, or the person
  responsible for delivering to the intended recipient, you should not read,
  copy, disclose or otherwise use this message, except for the purpose of
  delivery to the addressee. If you have received this email in error, please
  delete and advise us immediately.
  
  ___
  Haskell mailing list
  [EMAIL PROTECTED]
  http://www.haskell.org/mailman/listinfo/haskell
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell