问题描述
我正在学习 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 的情况下学习吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!