James's profileJames McCaffreyBlogLists Tools Help

Blog


    October 23

    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
      result
     
    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.
     

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://jamesmccaffrey.spaces.live.com/blog/cns!504C7CC53E7E7FE8!1416.trak
    Weblogs that reference this entry
    • None