Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:05:24+00:00 2026-05-28T04:05:24+00:00

I am playing a little bit with functional programming and the various concepts of

  • 0

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 advantage it has.

But I do not get the point with this. The following source demonstrates the using of the curry concept and the solution with linq. Actually, I do not see any advatages of using the currying concept.

So, what is the advantage of using currying?

static bool IsPrime(int value)
{
    int max = (value / 2) + 1;
    for (int i = 2; i < max; i++)
    {
        if ((value % i) == 0)
        {
            return false;
        }
    }
    return true;
}

static readonly Func<IEnumerable<int>, IEnumerable<int>> GetPrimes = 
        HigherOrder.GetFilter<int>().Curry()(IsPrime);

static void Main(string[] args)
{
    int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

    Console.Write("Primes:");
    //Curry
    foreach (int n in GetPrimes(numbers))
    {
        Console.Write(" {0}", n);
    }
    Console.WriteLine();

    //Linq
    foreach (int n in numbers.Where(p => IsPrime(p)))
    {
        Console.Write(" {0}", n);
    }

    Console.ReadLine();
}

Here is the HigherOrder Filter Method:

public static Func<Func<TSource, bool>, IEnumerable<TSource>, IEnumerable<TSource>> GetFilter<TSource>()
{
    return Filter<TSource>;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:05:25+00:00Added an answer on May 28, 2026 at 4:05 am

    what is the advantage of using currying?

    First off, let’s clarify some terms. People use "currying" to mean both:

    1. reformulating a method of two parameters into a methods of one parameter that returns a method of one parameter and
    2. partial application of a method of two parameters to produce a method of one parameter.

    Clearly these two tasks are closely related, and hence the confusion. When speaking formally, one ought to restrict "currying" to refer to the first definition, but when speaking informally either usage is common.

    So, if you have a method:

    static int Add(int x, int y) { return x + y; }
    

    you can call it like this:

    int result = Add(2, 3); // 5
    

    You can curry the Add method:

    static Func<int, int> MakeAdder(int x) { return y => Add(x, y); }
    

    and now:

    Func<int, int> addTwo = MakeAdder(2);
    int result = addTwo(3); // 5
    

    Partial application is sometimes also called "currying" when speaking informally because it is obviously related:

    Func<int, int> addTwo = y=>Add(2,y);
    int result = addTwo(3);
    

    You can make a machine that does this process for you:

    static Func<B, R> PartiallyApply<A, B, R>(Func<A, B, R> f, A a)
    {
        return (B b)=>f(a, b);
    }
    ...
    Func<int, int> addTwo = PartiallyApply<int, int, int>(Add, 2);
    int result = addTwo(3); // 5
    

    So now we come to your question:

    what is the advantage of using currying?

    The advantage of either technique is that it gives you more flexibility in dealing with methods.

    For example, suppose you are writing an implementation of a path finding algorithm. You might already have a helper method that gives you an approximate distance between two points:

    static double ApproximateDistance(Point p1, Point p2) { ... }
    

    But when you are actually building the algorithm, what you often want to know is what is the distance between the current location and a fixed end point. What the algorithm needs is Func<Point, double> — what is the distance from the location to the fixed end point? What you have is Func<Point, Point, double>. How are you going to turn what you’ve got into what you need? With partial application; you partially apply the fixed end point as the first argument to the approximate distance method, and you get out a function that matches what your path finding algorithm needs to consume:

    Func<Point, double> distanceFinder = PartiallyApply<Point, Point, double>(ApproximateDistance, givenEndPoint);
    

    If the ApproximateDistance method had been curried in the first place:

    static Func<Point, double> MakeApproximateDistanceFinder(Point p1) { ... }
    

    Then you would not need to do the partial application yourself; you’d just call MakeApproximateDistanceFinder with the fixed end point and you’d be done.

    Func<Point, double> distanceFinder = MakeApproximateDistanceFinder(givenEndPoint);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im playing a little bit with heavy-client app. Imagine I have this model: class
I've been playing around with Direct3D 11 a little bit lately and have been
Earlier it was working fine. I have been playing little bit config. So may
This surprised me a little bit, but I was playing around with some code
I'm playing a little bit with opengl programming on linux and I've some doubts.
currently I'm playing a little bit with spine.js I have red the documentation about
I have been playing around with SQLite a little bit and I was looking
Playing a little with coffeescript and Rails 3.1.0.rc4. Have this code: yourMom = (location)
I'm playing a little bit with the new StackOverflow API . Unfortunately, my JSON
I'm playing with Hibernate a little bit. I created a Group class and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.