gpt4 book ai didi

f# - 简单解析命令行参数

转载 作者:行者123 更新时间:2023-12-04 22:31:38 25 4
gpt4 key购买 nike

我想使用以下代码来限制只有一个参数。但是,我在 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."

最佳答案

命令行参数作为数组传递,而不是列表。

如果您只期望一个参数,请执行以下操作:

match argv with 
| [|first|] ->
// .... do something with first
| _ -> failwith "Must have only one argument."

关于f# - 简单解析命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20252167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com