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

  • Home
  • SEARCH
  • 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 165185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:52:35+00:00 2026-05-11T11:52:35+00:00

I’ve got a function in C#, and I’d like to port it (among some

  • 0

I’ve got a function in C#, and I’d like to port it (among some other stuff) over to F#, just for the sake of doing it. Unfortunately, I just hit a case for which there seems to be no way to express this in F#: Take this C# function

public static T Min<T>(params T[] p) where T : IComparable {     T m1 = p[0];      foreach (T v in p)     {         m1 = (m1.CompareTo(v) < 0) ? m1 : v;     }      return m1; } 

I’d thought this would be pretty easy, but I don’t understand how I would specify a variable argument list in F#. I have tried this:

let rec Min l =     match l with     | [] -> 0 // should throw exception here     | [v] -> v     | (h::t) -> min h (Min t) 

but calling that from C# expects a Microsoft.FSharp.Collections.List. Is it possible to get it expect a params T[], and if so, how?

  • 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. 2026-05-11T11:52:35+00:00Added an answer on May 11, 2026 at 11:52 am

    A params array is simply an array with an attribute, as Jon notes. Add the attribute before the parameter.

    let test ([<ParamArray>] arr : 'a array) =      if arr.Length = 0 then invalid_arg 'arr'     // .... 

    You don’t need to specify the type:

    let test ([<ParamArray>] arr) = ... // lets type inference do its thing 

    But… pattern matching doesn’t work on the array type. You could write an active pattern to help. Basically, you have to decide what’s more important: the F# code or the C# code. The same tradeoff will apply as you design higher order functions, use tuples, use discriminated unions, etc. C# can’t express most things, and F# doesn’t currently support some of the little bits of sugar C# has (Expression Tree writing in the compiler, for example).

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

Sidebar

Related Questions

No related questions found

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.