Testing Curried Functions

The new F# programming language allows you to write curried functions. I am not a fan of using curried functions, at least from my point of view as a software tester. By the way, the term "curried" comes from Haskell Curry, a mathematician. Consider this normal F# code:
printfn "\nBegin curried function demo\n"
let s1 = "Hello"
let s2 = "world"
let prependString p s =
  let result = p + s
let r1 = prependString "//" s1
let r2 = prependString "//" s2
printfn "r1 and r2 are %s %s \n" r1 r2
The result would be, as you’d expect "r1 and r2 are //Hello //World". Now here’s a way to use curried functions:
let curriedPrependSlashes =
  prependString "//"
let r3 = curriedPrependSlashes s1
let r4 = curriedPrependSlashes s2
printfn "r3 and r4 are %s %s \n" r3 r4
The result would be identical, "r3 and r4 are //Hello //World". From a usage point of view curried functions allow you to reduce the number of arguments passed to a function when the function is called. I don’t like this from a testing point of view because currying usually involves an extra call to a non-curried helper function, which makes testing a bit more opaque so to speak. In other words, the call:
let r1 = prependString "//" s1
is more clear to me as a tester than the call:
let r3 = curriedPrependSlashes s1
But, this is really more opinion than technical and some people whose opinions I respect think curried functions are great things.
This entry was posted in Software Test Automation. Bookmark the permalink.