Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simply parse command line args

Tags:

f#

I want to use the following code to restrict there is only one argument. However, I got the following error at first :: NIL?

Error   1   This expression was expected to have type
    string []    
but here has type
    'a list 
[<EntryPoint>]
let main argv = 

    match argv with 
    | first :: NIL -> 
         .... do something with first
    | _ -> failwith "Must have only one argument."
like image 647
ca9163d9 Avatar asked Dec 12 '22 09:12

ca9163d9


1 Answers

The command line arguments are passed as an array, not a list.

Do something like this if you expect exactly one argument:

match argv with 
| [|first|] -> 
     // .... do something with first
| _ -> failwith "Must have only one argument."
like image 171
Gus Avatar answered Dec 18 '22 00:12

Gus