[nem-bug] [Nemerle 0000638]: Co/contravariance for generic interfaces / delegates

feedback at nemerle.org feedback at nemerle.org
Mon May 8 22:23:57 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=638> 
======================================================================
Reported By:                steffen
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   638
Category:                   Compiler
Reproducibility:            always
Severity:                   feature
Priority:                   normal
Status:                     confirmed
======================================================================
Date Submitted:             03-25-2006 19:55 CET
Last Modified:              05-08-2006 22:23 CEST
======================================================================
Summary:                    Co/contravariance for generic interfaces / delegates
Description: 
It would be nice to have co/contravariance support for generic parameters
of interfaces and delegates.

I.e. you should be able to do something like this:

interface IEnumerator[[covariant] T] {
  Current : T { get; }
  MoveNext() : bool;
}

interface IComparer[[contravariant] T] {
  Compare(x : T, y : T);
}

delegate EventHandler[[contravariant] T](arg : T) : void;

(The examples are from the CLI Spec II 9.5)

Btw.: It seems tha ncc doesn't support attribute for type parameter, e.g.

public class attr : System.Attribute { }

public interface X[[attr] 'a] { }

fails to compile.
======================================================================

----------------------------------------------------------------------
 malekith - 03-25-06 20:44 
----------------------------------------------------------------------
We thought about this. I guess even SRE allows this, but we were affraid
mono SRE would just crash on it (and even if SRE supported this, the
runtime is probably not tested). Of course this is not a justficiation to
skip this feature :-)

----------------------------------------------------------------------
 nazgul - 05-03-06 18:29 
----------------------------------------------------------------------
We still need to invent the syntax ;)

I vote for  interface IList [T+] { }   and interface IFunc [F-,T+] { .. }

This feature seems to be not that hard to do, assuming that .NET runtimes
will actually handle it. Negative tests (rejecting incorrect annotations)
also looks doable. Maybe we should promote this feature to our
OpenProjects page, so it can get more attention?


----------------------------------------------------------------------
 VladD2 - 05-08-06 22:23 
----------------------------------------------------------------------
In Scala used 
IList [+T] { } 
syntax.

And what about co/contravariance and the ValueType type arguments?

Issue History
Date Modified  Username       Field                    Change              
======================================================================
03-25-06 19:55 steffen        New Issue                                    
03-25-06 20:44 malekith       Note Added: 0001123                          
05-03-06 18:29 nazgul         Note Added: 0001223                          
05-03-06 18:29 nazgul         Status                   new => confirmed    
05-03-06 18:29 nazgul         Description Updated                          
05-08-06 22:23 VladD2         Note Added: 0001255                          
======================================================================




More information about the bugs mailing list