www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12407] New: reduce cannot deduce argument types

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12407

           Summary: reduce cannot deduce argument types
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: lt.infiltrator gmail.com



PDT ---
http://dpaste.dzfl.pl/f2d178081ee8

-----------------------------------------------------------
import std.algorithm : map, reduce;

class A {
   long fun() {
      return 1 + sub.map!(s => s.fun()).reduce!((a, b) => a + b)(0L);
   }

   A[] sub;
}

void main() { }
----------------------------------------------------------
Fails to compile:
/d414/f619.d(5): Error: template std.algorithm.reduce cannot deduce function
from argument types !((a, b) => a + b)(MapResult!(__lambda1, A[]), long),
candidates are: /opt/compilers/dmd2/include/std/algorithm.d(701):
std.algorithm.reduce(fun...) if (fun.length >= 1)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12407


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bearophile_hugs eml.cc
         Resolution|                            |INVALID



I think this is an invalid issue. reduce currently takes as first argument the
seed and as second the range. This is the correct code:

return 1 + reduce!((a, b) => a + b)(0L, sub.map!(s => s.fun));

There are plans in fixing reduce.

Also voting your own entry, and doing it twice, is not so good :-)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12407




PDT ---
Of course.  I keep forgetting about that with reduce.

As for the voting, I use it to keep track of issues (I don't see a bookmark or
similar option), and I just spread my votes out evenly.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12407





 Of course.  I keep forgetting about that with reduce.
 
 As for the voting, I use it to keep track of issues (I don't see a bookmark or
 similar option), and I just spread my votes out evenly.
You can perform an advanced search, to find your own issues. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 18 2014