2

As a neophyte F# developer, I am trying to create a simple Excel-DNA function as follows:

[<ExcelFunction(Name="ACount", Description="Count items", Category="Misc Functions", IsThreadSafe = true)>]
let aCount (range: _[]) (filter: string) = 
    let result = 
        Seq.ofArray range
        |> Seq.filter (fun x -> x = filter)
        |> Seq.length
    result

but it generates the following error on loading to Excel 2016 (64-bit):

Initialization [Error] Method not registered - unsupported signature, abstract or generic:

What am I doing wrong?

matekus
  • 778
  • 3
  • 14
  • What happens if you replace `_[]` with `string []`? What is the type of the function of you hover on it? – Fyodor Soikin Sep 25 '17 at 14:51
  • Fyodor, Thanks for the quick follow-up. As requested: val aCount : range:string [] -> filter:string -> int – matekus Sep 25 '17 at 14:56
  • String arrays are not supported by Excel-DNA by default (without using the Registration extensions). Change to object[] arrays by casting the result valus to obj. – Govert Sep 25 '17 at 16:29
  • Govert, Are you saying I need to convert incoming string[] to object[] and / or outgoing int to object or both? – matekus Sep 25 '17 at 17:53
  • I mean it should work if the signature ends up being `val aCount : range:obj [] -> filter:string -> int`. Excel has conversions for int to double, but not for string arrays. – Govert Sep 25 '17 at 20:30

1 Answers1

1

Thanks Govert.

The following works but is it sufficiently idiomatic?

[<ExcelFunction(Name="ACount", Description="Count items", Category="Misc Functions", IsThreadSafe = true)>]
let aCount (range: obj[]) (filter: string) = 
    let result = 
        Seq.ofArray range
        |> Seq.filter (fun x -> string x = filter)
        |> Seq.length
    result

Any constructive changes welcome!

matekus
  • 778
  • 3
  • 14