Andrew Stopford's Weblog

poobah

Sponsors

News

Articles

Family

Old Blogs

generics covariance/contravariance support in C# [2]

Further to my last post on generics covariance/contravariance support in C# I have been researching this a bit more. I ran into this research paper that discusses a way of adding support to C# and suggests that a patch might be created for Rotor 2.0 so you can see this in action, does anyone know if this has been done? It seems that while the CLI supports generic covariance/contravariance I can't beyond Eiffel any .NET languages that support it (if you do know of any let me know), while cool I am not sure if Eiffel is free and for OSS purposes I can't afford it :)

One way of getting around this in C# is to use the CopyAll function, see this post on how. However note Rick Byers advice on this.

[CopyAll creates] a NEW list, calling the conversion function for EACH element, and storing the resulting element into the new list.  This is not the same thing as [generic covariance/contravariance].  First of all, copying the whole list to a new list takes time and space proportional to the size of the list.

Posted: Oct 09 2006, 10:39 PM by astopford | with 2 comment(s)
Filed under:

Comments

andrex said:

Try Nemerle: http://nemerle.org/

Contains all best of many languages. Based on C#. Support functional and imperative styles. Features like: functional values, lambda expressions, variants, pattern matching, powerful macros (not с++ macros!) and more...

Now some peoples hard work on VS2005 integration for this language.

# October 9, 2006 9:25 PM

Andrew Stopford's Weblog said:

Back in 2006 I wrote about the co\contra variance generics support in .NET , fast foward to today and

# February 26, 2008 7:08 AM