[Nemerle 0001089]: Cannot infer type for generic function

12 views
Skip to first unread message

feed...@nemerle.org

unread,
Dec 22, 2008, 6:46:58 AM12/22/08
to nemerl...@googlegroups.com

The following issue has been ASSIGNED.
======================================================================
<http://nemerle.org/bugs/view.php?id=1089>
======================================================================
Reported By: KLiss
Assigned To: VladD2
======================================================================
Project: Nemerle
Issue ID: 1089
Category: Compiler (type engine)
Reproducibility: always
Severity: minor
Priority: normal
Status: assigned
======================================================================
Date Submitted: 03-11-2008 20:13 CET
Last Modified: 12-22-2008 12:46 CET
======================================================================
Summary: Cannot infer type for generic function
Description:
using System;
using System.Collections.Generic;
using System.Console;
using Nemerle.Utility;
using Nemerle.Assertions;

module Program
{
Main() : void
{
WriteLine("Hi!");
}

public Flatten[TEnu, TElem] ([NotNull] this source :
IEnumerable[TEnu]) : IEnumerable[TElem]
where TEnu : IEnumerable[TElem]
{
foreach(elem1 in source)
foreach(elem2 in elem1 : IEnumerable[TElem]) // with this hint it
compiles fine. Should also compile without it!
yield elem2;
}
}
======================================================================

----------------------------------------------------------------------
KLiss - 03-11-08 20:18
----------------------------------------------------------------------
This is C# version (with test):

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;


static class A
{
static void Main()
{
foreach (var s in Flatten<List<string>, string>( Foo()))
Console.WriteLine(s);
Console.ReadKey();
}

private static IEnumerable<List<string>> Foo()
{
yield return new List<string> {"one", "two"};
yield return new List<string> { "foo", "bar", "zed" };
}

public static IEnumerable<TElem> Flatten<TEnu, TElem>(this
IEnumerable<TEnu> source)
where TEnu : IEnumerable<TElem>
{
foreach (var lst in source)
foreach (var elem in lst)
yield return elem;
}
}

----------------------------------------------------------------------
KLiss - 03-11-08 20:29
----------------------------------------------------------------------
By the way, Nemerle is still smarter than C#. It was able (with the hint)
to figure out that Flatten can be member of IEnumerable[List[string]] and
IEnumerable[array[string]] :-)

using System;
using System.Collections.Generic;
using System.Console;
using Nemerle.Utility;
using Nemerle.Assertions;
using Nemerle.Collections;


module Program
{
Main() : void
{
Foo().Flatten().Iter(WriteLine(_));
WriteLine("---");
Bar().Flatten().Iter(WriteLine(_));

_ = ReadKey();

}

private Foo() : IEnumerable[List[string]]
{
yield { def lst = List(); ["one", "two"].Iter(lst.Add(_)); lst;};
yield { def lst = List(); ["foo", "bar", "zed"].Iter(lst.Add(_));
lst;};
}

private Bar() : IEnumerable[array[string]]
{
yield array ["one", "two"];
yield array ["foo", "bar", "zed"];
}

public Flatten[TEnu, TElem] ([NotNull] this source : IEnumerable[TEnu])
: IEnumerable[TElem]
where TEnu : IEnumerable[TElem]
{
foreach(elem1 in source)
foreach(elem2 in elem1 : IEnumerable[TElem])
yield elem2;
}
}

----------------------------------------------------------------------
VladD2 - 03-14-08 05:34
----------------------------------------------------------------------
>By the way, Nemerle is still smarter than C#...

Nemerle support covariant for interfaces.

----------------------------------------------------------------------
nikov - 03-14-08 16:35
----------------------------------------------------------------------
> Nemerle support covariant for interfaces.

Interface covariance has nothing to do with this issue.
It is possible to write the same code in C# with explicit type argument
specification.

Issue History
Date Modified Username Field Change
======================================================================
03-11-08 20:13 KLiss New Issue
03-11-08 20:15 KLiss Description Updated
03-11-08 20:18 KLiss Note Added: 0002055
03-11-08 20:29 KLiss Note Added: 0002056
03-14-08 05:34 VladD2 Note Added: 0002061
03-14-08 16:35 nikov Note Added: 0002062
12-22-08 12:46 VladD2 Status new => assigned
12-22-08 12:46 VladD2 Assigned To => VladD2
======================================================================

feed...@nemerle.org

unread,
Dec 25, 2008, 5:27:15 AM12/25/08
to nemerl...@googlegroups.com

The following issue has been RESOLVED.

======================================================================
<http://nemerle.org/bugs/view.php?id=1089>
======================================================================
Reported By: KLiss
Assigned To: VladD2
======================================================================
Project: Nemerle
Issue ID: 1089
Category: Compiler (type engine)
Reproducibility: always
Severity: minor
Priority: normal
Status: resolved
Resolution: fixed
Fixed in Version:
======================================================================
Date Submitted: 03-11-2008 20:13 CET
Last Modified: 12-25-2008 11:27 CET

----------------------------------------------------------------------
VladD2 - 12-25-08 11:27
----------------------------------------------------------------------
Fixed in revision 8189.

Issue History
Date Modified Username Field Change
======================================================================
03-11-08 20:13 KLiss New Issue
03-11-08 20:15 KLiss Description Updated
03-11-08 20:18 KLiss Note Added: 0002055
03-11-08 20:29 KLiss Note Added: 0002056
03-14-08 05:34 VladD2 Note Added: 0002061
03-14-08 16:35 nikov Note Added: 0002062
12-22-08 12:46 VladD2 Status new => assigned
12-22-08 12:46 VladD2 Assigned To => VladD2

12-25-08 11:27 VladD2 Status assigned => resolved
12-25-08 11:27 VladD2 Resolution open => fixed
12-25-08 11:27 VladD2 Note Added: 0002162
======================================================================

Reply all
Reply to author
Forward
0 new messages