簡體   English   中英

fsharp中列表定義的差異

[英]Difference in List definition in fsharp

這沒問題

let staticParams = [ProvidedStaticParameter("filename", typeof<string>)
                    ProvidedStaticParameter("forcestring", typeof<bool>, false)]

但事實並非如此

let filename3 = ProvidedStaticParameter("filename", typeof<string>)
let forcestring = ProvidedStaticParameter("forcestring", typeof<bool>, false)

let staticParams = [filename3 
                   forcestring]

有什么區別 ? 然后,如果我鍵入它,它被正確識別為aggain

let filename3 = ProvidedStaticParameter("filename", typeof<string>)
let forcestring = ProvidedStaticParameter("forcestring", typeof<bool>, false)

let staticParams = [filename3 ;
                   forcestring]

; 是一種古老的語法(來自ML)。 除非您在同一行中鍵入多個元素(例如[ 1; 2 ] ),否則沒有理由使用它。 同樣在記錄中,你不必放; 在田野之間。

第二個代碼無法編譯,因為所有元素必須具有相同的縮進級別:

let staticParams = [filename3 
                    forcestring]

在F#中,縮進很重要。 例如:

let staticParams = [filename3
                    forcestring]

兩個值具有相同的縮進級別,它們被解析為列表元素。

但是在以下情況中:

let staticParams = [filename3 
                   forcestring]
//                 ^
//                 Notice different indentation here.

兩個值被解析為filename3forcestring函數應用程序,因此是一個錯誤消息。

既然; 是列表分隔符,在上一個示例中,F#parser期望下一行中的另一個列表元素。 因此,那里的錯誤縮進沒有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM