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 7098135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:01:04+00:00 2026-05-28T11:01:04+00:00

F# provides a feature, where a function can return another function. An example of

  • 0

F# provides a feature, where a function can return another function.

An example of function generating a function in F# is:

let powerFunctionGenarator baseNumber = (fun exponent -> baseNumber ** exponent);

let powerOfTwo = powerFunctionGenarator 2.0;

let powerOfThree = powerFunctionGenarator 3.0;

let power2 = powerOfTwo 10.0;
let power3 = powerOfThree 10.0;

printfn "%f" power2;
printfn "%f" power3;

The best way I could come up with to achieve the same in C# was this:

class Program
{
    delegate double PowerOf2(double exponent);
    delegate double PowerOf3(double exponent);
    delegate double PowerOfN(double n, double exponent);

    static void Main(string[] args)
    {
        PowerOfN powerOfN = (a, b) => { return Math.Pow(a,b) ; };
        PowerOf2 powerOf2 = (a) => { return powerOfN(2, a); };
        PowerOf3 powerOf3 = (a) => { return powerOfN(3, a); };

        double result = powerOf2(10);
        Console.WriteLine(result);
        result = powerOf3(10);
        Console.WriteLine(result);
    }
}

Is there some other way (/better way) of doing this?

  • 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-28T11:01:04+00:00Added an answer on May 28, 2026 at 11:01 am

    Sure, that’s straightforward in C#:

    using System;
    class P
    {
      static void Main()
      {
          Func<double, Func<double, double>> powerFunctionGenerator = 
              baseNumber => exponent => Math.Pow(baseNumber, exponent);  
    
          Func<double, double> powerOfTwo = powerFunctionGenerator(2.0);
          Func<double, double> powerOfThree = powerFunctionGenerator(3.0);
          double power2 = powerOfTwo(10.0); 
          double power3 = powerOfThree(10.0);
          Console.WriteLine(power2); 
          Console.WriteLine(power3);
      }
    }
    

    Easy peasy. And if you don’t like the manifest typing, most of those can be replaced with var.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haskell provides the feature something like f = f1 . f2 How can I
This code provides a simple rollover/rollout show|hide feature: $(document).ready(function () { $(div[class='lineItem']).hover(function () {
I have the follwing code that provides an auto refresh feature to a WCF
I use jQuery together with the dataTables Plugin. dataTables provides a feature to open
I'm struggling with a performance issue for a copy feature that my application provides
In the example below I have written one to_str() function and one set() procedure
I have a need of a function/library that can quickly encrypt an image on
I was searching for a BinaryReader.Skip function, while I came across this feature request
Sometimes, I come across certain web development frameworks which don't provide an authentication feature,
I need to implement a feature similar to the one provided by Microsoft Outlook

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.