3

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.

Janthelme
  • 989
  • 10
  • 23

2 Answers2

4

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
Jim Foye
  • 1,918
  • 1
  • 13
  • 15
1

For Registration samples

ParameterConversionConfiguration() .AddReturnConversion(fun (values: double[]) -> Array.map (string >> box) values )

humhei
  • 11
  • 2