Benx Blog

三月 3, 2007

Diigo Diary Bookmarks 03/02/2007

分類於 Diigo Diary — benxshen @ 8:30 上午

Currying - Wikipedia, the free encyclopedia  Annotated

    In mathematics, computer science and linguistics (semantics), currying or Schönfinkelisation[1] is the technique of transforming a function that takes multiple arguments into a function that takes a single argument (the other arguments having been specified by the curry).

      ML

      Suppose that plus is a function taking two arguments x and y and returning x + y. In the ML programming language we would define it as follows:

         plus = fn(x, y) => x + y
      

      and plus(1, 2) returns 3 as we expect.

      The curried version of plus takes a single argument x and returns a new function which takes a single argument y and returns x + y. In ML we would define it as follows:

         curried_plus = fn(x) => fn(y) => x + y
      

      and now when we call curried_plus(1) we get a new function that adds 1 to its argument:

         plus_one = curried_plus(1)
      

      and now plus_one(2) returns 3 and plus_one(7) returns 8.

        JavaScript currying

          零則回應 »

          目前無回應內容

          RSS訂閱此篇文章的迴響 引用網址

          留言

          在WordPress.com寫網誌.