Reputation: 999
In F# / Excel-Dna, what is the idiomatic way to rewrite the following function for a vector of strings? (i.e. a function which sorts a "vector" (=1d Excel range) of strings).
[<ExcelFunction(Category="Some Cat", Description="Sort 1d range filled with doubles.")>]
let mySortDouble (vect : double[]) : double[] =
Array.sort vect
If I merely replace the double types with string types in the above snippet, I get this error message : Initialization [Error] Method not registered - unsupported signature, abstract or generic: 'MyFSFunctions.mySortString'
I saw this previous question where Govert suggests to use the "Registration extensions" but I have not found how to use it to answer my current question.
Upvotes: 3
Views: 141
Reputation: 11
ParameterConversionConfiguration()
.AddReturnConversion(fun (values: double[]) ->
Array.map (string >> box) values
)
Upvotes: 1
Reputation: 2036
As you have mySortDouble written, it won't even compile, because it returns a double[], not a double.
Here's an example that works, with some minimal error handling added.
[<ExcelFunction(Category="Some Cat", Description="Sort 1D range of strings.")>]
let SortStrings (vect : obj[]) =
try
vect
|> Seq.cast<string>
|> Seq.sort
|> Seq.toArray
|> box
with
| ex -> box ExcelError.ExcelErrorNA
Upvotes: 4