我正在尝试读取输入文件的名称argv [1]。这就是我到目前为止所做的:
val args = CommandLine.arguments() ;
val (x::y) = args ;
val _ = agora x
但我不断收到此错误消息:
uncaught exception Bind [nonexhaustive binding failure] .
有人可以帮忙吗?提前谢谢!
答案 0 :(得分:2)
这是编译器警告您无法确定绑定模式是否始终存在。
例如,给定以下程序:
id
编译并运行它会给出:
SELECT CONCAT(tbl_persons.name,' ',tbl_persons.last_name,' ',tbl_persons.last_sname) as fullname, tbl_appointment.*
FROM tbl_appointment
INNER JOIN tbl_persons ON tbl_persons.idpersons = tbl_appointment.idemployee
INNER JOIN tbl_persons ON tbl_persons.idpersons = tbl_appointment.idclient
WHERE idclient= '$user';
为了安全地处理可变数量的命令行参数,您可以使用 case-of :
val args = CommandLine.arguments ()
val (x::y) = args
val _ = print (x ^ "\n")
编译并运行它会给出:
$ mosmlc args.sml
$ ./a.out Hello
Hello
$ ./a.out
Uncaught exception:
Bind
附注:C&#39 {s} fun main () =
case CommandLine.arguments () of
[] => print ("Too few arguments!\n")
| [arg1] => print ("That's right! " ^ arg1 ^ "\n")
| args => print ("Too many arguments!\n")
val _ = main ()
的等价物是$ mosmlc args2.sml
$ ./a.out
Too few arguments!
$ ./a.out hello
That's right! hello
$ ./a.out hello world
Too many arguments!
。