2

I am new to F# and I need an example of currying.

Is it currying or partial application?

let multiplyByThree x =
    let multiply y = 
        y * x
    multiply 3

let result = multiplyByThree 3 // 9
lapots
  • 12,553
  • 32
  • 121
  • 242

1 Answers1

2

Partial application is a process, well, of creating partially applied function, e.g.:

let sum x y = x + y // sum is a curried function, it's default in F#
let sum4 x = sum 4 x // partial application

Currying is an ability to represent a function with multiple arguments as a sequence of functions taking single argument and returning a function as well.

However, if you're working with .NET functions, they accept their arguments as tuples, e.g.:

let sum (x,y) = x + y
// let sum4 x = sum 4 x // can't do that!
let sum4 x = sum (4,x) // this is valid. passing a tuple
yuyoyuppe
  • 1,582
  • 2
  • 20
  • 33