我刚开始学习 F#,并尝试了 the wiki 中的代码:
我更喜欢制表符而不是空格,所以我将代码更改为:
#indent "off"
open System
open System.Windows.Forms
let form = new Form(Visible=true, TopMost=true, Text="Welcome to F#")
let label =
let temp = new Label()
let x = 3 + (4 * 5)
temp.Text <- sprintf "x = %d" x
temp
form.Controls.Add(label)
[<STAThread>]
Application.Run(form)
输出是:
Microsoft (R) F# 2.0 Compiler build 4.0.30319.1 Copyright (c) Microsoft Corporation. All Rights Reserved.
fstest2.fs(1,1): warning FS0062: This construct is for ML compatibility. Conside r using a file with extension '.ml' or '.mli' instead. You can disable this warn ing by using '--mlcompatibility' or '--nowarn:62'.
fstest2.fs(9,2): error FS0010: Unexpected keyword 'let' or 'use' in expression. Expected 'in' or other token.
fstest2.fs(13,1): error FS0597: Successive arguments should be separated by spac es or tupled, and arguments involving function or method applications should be parenthesized
fstest2.fs(9,14): error FS0374: Invalid expression on left of assignment
fstest2.fs(16,1): error FS0010: Unexpected identifier in definition
猜猜错误在中的某处让标签 阻止,但无法弄清楚。
最佳答案
如果您使用“#indent off”,那么您将丢失所有更简单的空格感知语法,并且必须重新使用例如
#indent "off"
open System
open System.Windows.Forms
let label =
let temp = new Label() in
let x = 3 + (4 * 5) in
temp.Text <- sprintf "x = %d" x;
temp;;
let form =
let f = new Form() in
f.Controls.Add(label);
f;;
[<STAThread>]
do Application.Run(form)
带分号和
in
s 和所有其他类型的句法噪音无处不在。您可能会更高兴让您的编辑器将制表符转换为空格(并拥有一个可以将空格视为制表符的智能编辑器,例如,退格可以备份一个制表位)。
关于f# - #indent "off"在 F#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2745759/