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

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

          發表迴響

          在下方填入你的資料或按右方圖示以社群網站登入:

          WordPress.com Logo

          You are commenting using your WordPress.com account. Log Out / 變更 )

          Twitter picture

          You are commenting using your Twitter account. Log Out / 變更 )

          Facebook照片

          You are commenting using your Facebook account. Log Out / 變更 )

          Google+ photo

          You are commenting using your Google+ account. Log Out / 變更 )

          連結到 %s

          在 WordPress.com 建立免費網站或網誌.

          %d 位部落客按了讚: