Thread overview
[Issue 13304] std.algorithm.reduce: "Unable to deduce an acceptable seed type" with float[]
Aug 16, 2014
Vladimir Panteleev
Oct 04, 2014
Martin Nowak
August 16, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--
August 16, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com

--- Comment #1 from monarchdodra@gmail.com ---
(In reply to Vladimir Panteleev from comment #0)
> /////////////////// test.d ///////////////////
> import std.algorithm;
> 
> void main()
> {
>     float[] nums;
>     float sum = reduce!((a,b) => a + b)(nums);
> }
> //////////////////////////////////////////////
> 
> Introduced in https://github.com/D-Programming-Language/phobos/pull/2060

Seems its a glitch in the way the assertion code is written. The good news is there is no logical fallacy in the algorithm.

I'll give it a quick fix.

--
August 16, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

--- Comment #2 from monarchdodra@gmail.com ---
(In reply to monarchdodra from comment #1)
> I'll give it a quick fix.

It turns out there is something that is making the compiler complain in my tests, because it is trying to *actually* evaluate the predicate in test (rather than just check compilability). This triggers it, because it complains it has no access to source code. What's funny is that it works fine with string predicate:

float sum = reduce!(binaryFun!"a + b")(nums); //OK!
float sum = reduce!((a,b) => a + b)(nums);    //NOPE!

This is weird. I wonder if there isn't another related regression or something.

I'm gonna try to reduce.

--
August 16, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

--- Comment #3 from monarchdodra@gmail.com ---
OK: Is this a rejects valid?

//----
import std.functional;

void main(string[] args)
{
    foo!(binaryFun!"a + b")();
    foo!((a,b) => a + b)();
}

void foo(alias pred)()
{
    alias A = Test1!int.Test2!pred;
}

template Test1(E)
{
    template Test2(alias pred)
    {
    }
}
//----
Error: template instance Test2!(__lambda2) cannot use local '__lambda2' as
parameter to non-global template Test2(alias pred)
Error: template instance main.main.foo!((a, b) => a + b) error instantiating

It doesn't quite explain the issue, but it still seems strange to me. my lambda doesn't require context, so it shouldn't considered "local", should it? Also, I don't understand the issue about "Global" template.

--
August 16, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

--- Comment #4 from Vladimir Panteleev <thecybershadow@gmail.com> ---
(In reply to monarchdodra from comment #3)
> Error: template instance Test2!(__lambda2) cannot use local '__lambda2' as
> parameter to non-global template Test2(alias pred)
> Error: template instance main.main.foo!((a, b) => a + b) error instantiating

Try adding "static" to Test1 or Test2. Probably related to issue 11946.

> It doesn't quite explain the issue, but it still seems strange to me. my lambda doesn't require context, so it shouldn't considered "local", should it? Also, I don't understand the issue about "Global" template.

Yes, doesn't seem right. File it and maybe Kenji will look at it.

--
October 04, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu

--- Comment #5 from Martin Nowak <code@dawg.eu> ---
Any fix in sight?

--
October 04, 2014
https://issues.dlang.org/show_bug.cgi?id=13304

monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from monarchdodra@gmail.com ---
(In reply to Martin Nowak from comment #5)
> Any fix in sight?

Sorry, the issue is fixed. https://github.com/D-Programming-Language/phobos/pull/2431

I still need to file the "Global template" issue though.

--