F# 关于F中元组和用户输入的问题#

F# 关于F中元组和用户输入的问题#,f#,F#,我正试着和f#玩游戏,从基础做起,但却被卡住了。如果您有一般提示,将不胜感激 #light open System [<EntryPoint>] let main (args : string[]) = match args with | [| firstName; lastName; city |] -> printfn "Hi there %s %s from %s" firstName lastName city 0 |

我正试着和f#玩游戏,从基础做起,但却被卡住了。如果您有一般提示,将不胜感激

#light
open System
[<EntryPoint>]
let main (args : string[]) = 
match args with
    | [| firstName; lastName; city |] ->
        printfn "Hi there %s %s from %s" firstName lastName city
        0
    | _ -> failwith "Usage: HiThere.exe firstName lastName City";;

我在看一个关于f#的教程,并试图学习这个函数,但我不明白为什么没有这些错误我就做不到。

args.[0],args.[1]中有一个非常小的输入错误。args.[2]
。在第二个和第三个元素之间有一个
,而不是一个
——它应该是
args.[0],args.[1],args.[2]

编译器仍然能够解析它,但它会将您的代码解释为:

args.[0], (args.[1].args.[2])
这在语法上是一个两元素的元组,您将其分配给一个三元素的元组,因此首先会得到关于元组的错误。它稍后会失败,因为
args
不是
args.[1]
的成员,但这是一条单独的消息(编译器会忽略该消息,因为它会报告先前找到的消息)

作为补充说明,您还可以在阵列上使用模式匹配并写入:

let main (args : string[]) = 
    match args with
    | [| firstName; lastName; city |] ->
        printfn "Hi there %s %s from %s" firstName lastName city
        0
    | _ -> failwith "Usage: HiThere.exe firstName lastName City"

你想知道为什么或者如何修复它,请问你真正想要答案的问题。哪个教程?这将有助于我们理解您未来的问题。
让sumOfSquaresI nums=let mutable acc=0 for x in nums做acc谢谢!运行时仍然有困难。您可能还需要使用
[]
属性标记
main
函数。是的,我的主代码中有这个属性,但在编写时它没有显示出来。
let main (args : string[]) = 
    match args with
    | [| firstName; lastName; city |] ->
        printfn "Hi there %s %s from %s" firstName lastName city
        0
    | _ -> failwith "Usage: HiThere.exe firstName lastName City"