Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement variable arguments in F#

Tags:

f#

I want to implement a F# function which may accept 1 or 2 arguments. I would like to use the function like this:

let foo = ...
foo "a"
foo "a" "b"

Both the arguments can be the same type. I read the pages about match pattern, active pattern, but cannot find one works for me.

like image 669
David S. Avatar asked Apr 26 '12 05:04

David S.


1 Answers

I believe this is due to some of the underlying .Net features, but I think you have to use a class with overloaded methods - something like

 type t() =
     static member foo a = "one arg"
     static member foo (a,b) = "two args"
like image 59
John Palmer Avatar answered Oct 19 '22 11:10

John Palmer