Implementing IEnumerable[T]

5 views
Skip to first unread message

Jet Blazer

unread,
Nov 7, 2008, 11:25:53 PM11/7/08
to Nemerle Forum
I am basically trying to implement a generic IEnumerable[T].
IEnumerable[T] requires two GetEnumerator() definitions.

In C#, it would look something like this:

using System.Collections.Generic;

IEnumerator<foo> IEnumerable<foo>.GetEnumerator()
{
return bar;
}

IEnumerator IEnumerable.GetEnumerator()
{
return bar;
}

I did the equivalent of that in Nemerle:

using System.Collections.Generic;

GetStrongEnumerator () : IEnumerator[foo] implements
IEnumerable[foo].GetEnumerator
{
bar;
}

GetWeakEnumerator () : IEnumerator implements
IEnumerable.GetEnumerator
{
bar;
}

The first method (GetStrongEnumerator) compiled fine. However, I am
getting an error in the second method (GetWeakEnumerator): wrong
number of type parameters to 'IEnumerator'

After inspecting it a bit further, the definition of IEnumerator
points to System.Object. That is, if I just hit "Go To Definition", it
simply point to System.Object rather than
System.Collections.IEnumerator which is understandable since I didn't
import System.Collections.

If I import System.Collections, Nemerle complaints about ambiguous
naming for IEnumerable eventhough one of the class is generic and the
other is a normal class which looks like a bug.

If specify IEnumerator by using its fully qualified name:

GetWeakEnumerator () : System.Collections.IEnumerator implements
IEnumerable.GetEnumerator

I get an error: interface `System.Collections.Generic.IEnumerable'
does not contain method named `GetEnumerator' with proper signature
which also looks like a bug.

So, in the end, how can you ever implement a
System.Collections.Generic.IEnumerable[T] interface in Nemerle?

Thanks,
Rahul
(sorry if this seems newbish, just starting working with Nemerle
recently)

VladD2

unread,
Nov 8, 2008, 11:58:31 AM11/8/08
to nemer...@googlegroups.com
Use qualified name for System.Collections.IEnumerable:

using System.Console;
using SC = System.Collections;
using System.Collections.Generic;

class Test : IEnumerable[int]
{
GetStrongEnumerator () : IEnumerator[int] implements
IEnumerable[int].GetEnumerator
{
[1, 2, 3].GetEnumerator();
}

GetWeakEnumerator () : SC.IEnumerator implements SC.IEnumerable.GetEnumerator
{
GetStrongEnumerator();
}
}

module Program
{
Main() : void
{
def res = Test();
WriteLine($"..$res");
_ = ReadLine();
}
}


2008/11/8 Jet Blazer <JetB...@gmail.com>:

--
С уважением,
Чистяков Владислав,
www.rsdn.ru

Jet Blazer

unread,
Nov 9, 2008, 2:35:04 AM11/9/08
to Nemerle Forum
wow, can't beleive I was being so stupid.

Thanks for the quick reply. Nemerle is a great language! Keep up with
the good work.

On Nov 8, 9:58 pm, VladD2 <v...@rsdn.ru> wrote:
> Use qualified name for  System.Collections.IEnumerable:
>
> using System.Console;
> using SC = System.Collections;
> using System.Collections.Generic;
>
> class Test : IEnumerable[int]
> {
>   GetStrongEnumerator () : IEnumerator[int] implements
> IEnumerable[int].GetEnumerator
>   {
>      [1, 2, 3].GetEnumerator();
>   }
>
>   GetWeakEnumerator () : SC.IEnumerator implements SC.IEnumerable.GetEnumerator
>   {
>     GetStrongEnumerator();
>   }
>
> }
>
> module Program
> {
>   Main() : void
>   {
>     def res = Test();
>     WriteLine($"..$res");
>     _ = ReadLine();
>   }
>
> }
>
> 2008/11/8 Jet Blazer <JetBla...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages