2012-02-28 109 views
1

该工程确定差异列表定义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] 

回答

2

;是一个古老的语法(从ML推出)。没有理由使用它,除非您在同一行中键入多个元素(例如[ 1; 2 ])。同样在记录中,您不必在域之间放置;

第二个代码不会编译,因为所有的元素都必须有相同的缩进级别:

let staticParams = [filename3 
        forcestring] 
2

在F#中,缩进是显著。例如:

let staticParams = [filename3 
        forcestring] 

两个值具有相同的缩进级别,它们被解析为列表元素。

然而,在下面的情况:

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

两个值被解析为filename3功能应用到forcestring并因此错误消息。

由于;是列表分隔符,在您的最后一个示例中,F#解析器需要下一行中的另一个列表元素。因此,这里没有错误的缩进问题。

+0

确实。格拉西亚斯 – nicolas 2012-02-28 11:14:24