f# - #indent "off"在 F#

标签 f# indentation

我刚开始学习 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/

相关文章:

recursion - 具有递归的 F# 求和类型?

f# - 如何使用拖放读取 Fable Elmish 中的 Browser.Blob

Python 缩进错误 : unexpected indent

python - Python 中的缩进样式 : Reverse Words Function

csv - 在 F# 中使用 FileHelperAsyncEngine

android - Xamarin/安卓 : F# scoping - how do I see a namespace in a different file?

android - 使用 Xamarin Android 与 F# 和 ReactiveUI 时出现运行时错误

parsing - 是否可以使用 fparsec 解析 "off-side"(基于缩进的)语言?

css - 使用缩进使 CSS 更具可读性? (使 parent 和 child 在 CSS 中更容易识别)

if-statement - Haskell 函数返回列表中出现次数超过给定数量的元素列表