C# Linq vs. Currying

前端 未结 3 531
南笙
南笙 2021-01-31 20:45

I am playing a little bit with functional programming and the various concepts of it. All this stuff is very interesting. Several times I have read about Currying and what an ad

3条回答
  •  故里飘歌
    2021-01-31 21:27

    The comment by @Eric Lippert on What is the advantage of Currying in C#? (achieving partial function) points to this blog post:

    Currying and Partial Function Application

    Where I found this the best explantion that works for me:

    From a theoretical standpoint, it is interesting because it (currying) simplifies the lambda calculus to include only those functions which have at most one argument. From a practical perspective, it allows a programmer to generate families of functions from a base function by fixing the first k arguments. It is akin to pinning up something on the wall that requires two pins. Before being pinned, the object is free to move anywhere on the surface; however, when when first pin is put in then the movement is constrained. Finally, when the second pin is put in then there is no longer any freedom of movement. Similarly, when a programmer curries a function of two arguments and applies it to the first argument then the functionality is limited by one dimension. Finally, when he applies the new function to the second argument then a particular value is computed.

    Taking this further I see that functional programming essentially introduces 'data flow programming as opposed to control flow' this is akin to using say SQL instead of C#. With this definition I see why LINQ is and why it has many many applications outside of pure Linq2Objects - such as events in Rx.

提交回复
热议问题