instances in Haskell-2

1998-07-29 Thread S.D.Mechveliani

To my request on Haskell-2

 ...
  class (Ring r,AddGroup (m r)) = RightModule m r  
where  
cMul :: m r - r - m r
  -- "vector" (m r) multiplied by "coefficient"  r'
 ...
  instance Ring r = RightModule r r  where  cMul = mul

 Haskell rejects this  `= RightModule r r'



Simon P. Jones [EMAIL PROTECTED]   replies

 This is fine too (for Haskell 2). See the same URL.

(http://www.dcs.gla.ac.uk/~simonpj/multi-param.html)


I cannot find there the subject. Could you citate?
The matter is not in repeating variables  r r  but in that the type 
variable  r  is set in the place of the constructor variable  m. 

This is to express the meaning   instance...= RightModule Id r 
with 
 transparent_newtype Id a = a


--
Sergey Mechveliani
[EMAIL PROTECTED]








Re: instances in Haskell-2

1998-07-29 Thread Simon L Peyton Jones

 I cannot find there the subject. Could you citate?

Sorry, it turns out I missed your point entirely.  

  class (Ring r,AddGroup (m r)) = RightModule m r where  
cMul :: m r - r - m r

So here, m :: *-*

What you really want is to say

  instance Ring r = RightModule (\t-t) r where
 cMul = mul

so that now you can use cMul at type

cMul :: Foo - Foo - Foo

(provided Foo is an instance of Ring).



The '(\t-t)::*-*' is your 'transparent newtype' function.  It makes
perfect sense to have lambda abstractions at the type level;
indeed type synonyms define such things.  I've seen quite a few
other occasions in which I wanted a (\t-t) type constructor 
in particular.

What I don't know how to do is to perform type inference on such systems.  (The
restriction that type synonyms must be fully applied is to avoid lambdas in
type inference.)  There is some work on it, but I believe the story is "It's
complicated".


So, yes it's a reasonable question, but I for one don't know
a tractable design.  And it's known swampy territory.

sorry for missing the point the first time.

Simon