Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F#: check if a value is an array of strings, an array of arrays of string or a string

Tags:

f#

I need use match to check if a value is an array of strings or a string. I've tried something in the vain of

| :? string[] -> ..
| :? string -> ..
| :? array<string[]> -> ..

but invain.

Any help?

like image 397
pistacchio Avatar asked Dec 28 '22 12:12

pistacchio


1 Answers

You need to modify the syntax slightly, but you were almost correct

let fn (arg:obj) = 
    match arg with
    | :? string as str -> printfn "string"
    | :? (string[]) as arr -> printfn "string array"
like image 92
John Palmer Avatar answered May 09 '23 01:05

John Palmer