Benx Blog

三月 3, 2007

Diigo Diary Bookmarks 03/02/2007

Filed under: 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).


      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 feed for comments on this post. TrackBack URI




          您的留言將使用 帳號。 登出 /  變更 )

          Google+ photo

          您的留言將使用 Google+ 帳號。 登出 /  變更 )

          Twitter picture

          您的留言將使用 Twitter 帳號。 登出 /  變更 )


          您的留言將使用 Facebook 帳號。 登出 /  變更 )


          連結到 %s

          在 建立免費網站或網誌.

          %d 位部落客按了讚: