【发布时间】:2019-08-06 19:55:09
【问题描述】:
在 F# 中创建命令行菜单时出错。函数本质上应该将 char(string) 转换为 num 并运行 = 代码。
Module Main =
let rec commandmenu() =
printfn "Select a command"
printfn "1. Word count Command - Word count"
printfn "2. Word count Command help"
printfn "3. Touch Command - Touch file"
printfn "4. Touch Command help"
printfn "5. Version"
printfn "6. Quit"
printfn "--------------------------------"
printfn "Select option (Eg '1','5') "
let optionselect = Console.ReadLine()
match System.Int32.TryParse optionselect with
| (true, number) when number = 1
-> wordcount()
// printf"Press any key to continue"
| (true, number) when number = 2
-> wordcounthelp()
| (true, number) when number = 3
-> touch()
| (true, number) when number = 4
-> touchhelp()
| (true, number) when number = 5
-> version()
| (true, number) when number = 6
-> 0 //Exit code
我不希望我的选项能够正常运行,因为它们还没有被正确编码,但是这个错误完全阻止了构建。当然包括开放系统。
【问题讨论】:
-
仅供参考,您可以直接匹配数字文字,例如
| (true, 1) -> wordcount()。您没有处理其他数字,或者布尔值是false的情况。 -
您是否尝试过“模块”而不是您在此处显示的内容(“模块”)?
-
假设带有大写 M 的
Module是一个错字,ideone.com/zUXIdO 我必须添加虚拟函数,但这编译得很好。你有什么错误确切地? -
你可以使用像 Argu 这样的命令行库或其他东西。