3

I feel like this is the chicken and egg problem. To make the comparison:

Currying:

x => y => z => u => value

Partial Application:

f_ab = (z,u) => value

From my understanding:

  1. Currying creates a chain of unary functions.
  2. Partial Application operates with functions of any arity.

Examples

const partial = 
    ( f, ...argList1 ) =>
    ( ...argList2 ) =>
    f( ...argList1, ...argList2 );

const curry1 = f => a => (...rest) => f( a, ...rest );
const curry2 = f => a => b => (...rest) => f( a, b, ...rest );  

const curry = f => curryN( f, [] );
const curryN =
    ( f, acc ) =>
    acc.length === f.length ?
    f( ...acc ) :
    arg => curryN( f, [ ...acc, arg ] ); 

 // Application sequence:
// curry( volume )
// curryN( volume, [] )
// a => curryN( volume, [a] )
// a => b => curryN( volume, [a, b] )
// a => b => c => curryN( volume, [a, b, c] )
// a => b => c => volume( a, b, c )


 const volume = ( a, b, c ) => a * b * c;

 console.log( 'partial', partial( volume, 2, 3 )( 4 ) );
 console.log( 'curry', curry( volume )( 2 )( 3 )( 4 ) );
nkr
  • 3,026
  • 7
  • 31
  • 39
  • 1
    What's the question ? – Mosè Raguzzini Dec 21 '17 at 07:39
  • 1
    The question is what the difference is between partial application and currying. He mentioned what his understanding is, and now he's waiting on someone to confirm or deny+correct him. – Vergil Penkov Dec 21 '17 at 07:45
  • https://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application – Bergi Dec 21 '17 at 08:47
  • I do not understand what you mean by "*x => y => z => u => value*" or "*f_ab = (z,u) => value*", but your JS implementation appears to be correct. – Bergi Dec 21 '17 at 08:50

0 Answers0