Thread overview
[Issue 3531] New: 'curry' doesn't work for templated functions
Nov 20, 2009
Max Samukha
Nov 20, 2009
Max Samukha
November 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3531

           Summary: 'curry' doesn't work for templated functions
           Product: D
           Version: 2.036
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: samukha@voliacable.com


--- Comment #0 from Max Samukha <samukha@voliacable.com> 2009-11-20 03:56:04 PST ---
auto add(A, B)(A x, B y)
{
    return x + y;
}

void main()
{
    alias curry!(add, 5) add5;
    assert(add5(6) == 11);
}

test.d(57): Error: template std.functional.curry!(add,5).curry(T) if
(is(typeof(fun(arg,T.init)))) does not match any fu
nction template declaration
test.d(57): Error: template std.functional.curry!(add,5).curry(T) if
(is(typeof(fun(arg,T.init)))) cannot deduce templat
e function from argument types !()(int)

The problem is with the constraint for curry(T)(T arg2). Remove the constraint
to workaround.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3531


Lars T. Kyllingstad <bugzilla@kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@kyllingen.net


--- Comment #1 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2009-11-20 06:29:58 PST ---
The is(typeof(...)) constraint can be replaced with __traits(compiles, ...).
This works:

    auto curry(T)(T arg2) if (__traits(compiles, { fun(arg, T.init); }))
    {
        return fun(arg, arg2);
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3531



--- Comment #2 from Max Samukha <samukha@voliacable.com> 2009-11-20 08:17:09 PST ---
Just want to note that it is not __traits(compiles) that makes the example work, but the function being wrapped in the delegate literal. This works as well:

auto curry(T)(T arg2) if (is(typeof( { fun(arg, T.init); } )))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3531


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com


--- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-11-20 10:05:39 PST ---
Thanks much.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3531


Andrei Alexandrescu <andrei@metalanguage.com> changed:

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


--- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-01-08 23:29:44 PST ---
Fixed a while ago. Added unittest with 2287.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------