2017-04-16 110 views
1

A Peek into F# 4.1,筆者展示了我們可以打印到的字符串不sprintf打印到的字符串不sprintf的

let private tryParseWith tryParseFunc (s : string) = 
    match (tryParseFunc s) with 
    | true, x -> Ok x 
    | false, _ -> Error ("%s is not capable of being parsed." s) 

我不能用sprintf因爲編譯器是聰明的推斷StringFormat<string>類型和評估表達式F#4.1和更新版本中的值爲string

+0

它是C#還是F#?你用C#編寫了這個問題 –

+0

@KfirGuy C#6支持'FormattableString'類型來插入字符串,所以我想知道F#是否也可以插入'sprintf'。 – MiP

+0

這只是示例代碼中的一個錯字。 –

回答

1

字符串插值當前不是可以在F#中找到的功能(截至版本4.1)。

有關當前字符串插值建議,請參見https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1001-StringInterpolation.md

+0

如果尚未得到支持,上述表達式如何評估'(「%s不能被解析。」s)'? – MiP

+0

對我來說,這似乎是博客文章中示例代碼中的一個錯誤。在那裏寫了一篇評論,要求澄清。 Skimmed https://github.com/fsharp/fslang-design/blob/master/FSharp-4.1/FS-1004-result-type.md和https://github.com/Microsoft/visualfsharp/pull/964/files ,並沒有發現證據表明字符串插值被實現到這個特性中。 –