问题描述
我正在学习F#,到目前为止,我很喜欢它.几乎所有在线示例都使用轻量级语法(#light);但是,在大多数情况下,也请为该示例提供注释.
I'm in the process of learning F# and am enjoying it so far. Almost all of the examples online use the lightweight syntax (#light); however, also give a comment about it being on for said example in most cases.
使用启用或禁用#light的F#学习更好吗?我打算最终在不启用它的情况下对其进行学习,但很好奇是从一开始学习它还是在我对核心语言有更多了解之后继续应用它会更好.
Is it better to learn F# using #light enabled or disabled? I'm planning on eventually learning it w/o it turned on but am curious on if it would be better to learn it at the beginning or work on applying it after I know the core language more.
推荐答案
我绝对希望使用#light语法学习F#.非简明版本有时对于理解有关F#语法的一些技巧很有用,但是#light语法可为您带来许多愉悦的体验.
I'd definitely prefer learning F# with the #light syntax. The non-light version is sometimes useful for understanding some tricks about the F# syntax, but the #light syntax gives you much pleasant experience.
例如-使用#light
For example - using #light
let add a b c =
let ab = a + b
printfn "%d" ab
c - ab
使用非光照,您可以编写如下内容:
Using non-light you can write the same thing like this:
let add a b c =
let ab = a + b in // 'in' keyword specifies where the binding (value 'ab') is valid
printfn "%d" ab; // ';' is operator for sequencing expressions
c - ab;; // ';;' is end of a function declaration
例如,这表明您不能编写类似的内容:
This for example shows that you cannot write something like:
let doNothing a b =
let sum = a + b in
最后有一个'in'关键字,但是该函数没有任何主体(因为'in'之后没有表达式).在这种情况下,有时可以理解非轻量级语法,这对于了解正在发生的事情很有帮助.但是,正如您所看到的,#light代码要简单得多.
There is an 'in' keyword at the end but the function doesn't have any body (because there is no expression following 'in'). In this case non-light syntax is sometimes interesting to understand what's going on... But as you can see, the #light code is a lot simpler.
这篇关于F#-是否应该学习#light?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!