簡體   English   中英

F#類型注釋問題

[英]F# Type annotation issue

我是F#開發的新手。 嘗試編譯示例源代碼時出現錯誤。 我有以下代碼

let tryParseWith tryParseFunc = tryParseFunc >> function
         | true, v    -> Some v
         | false, _   -> None

let tryParseInt32    = tryParseWith System.Int32.TryParse
let tryParseInt64    = tryParseWith System.Int64.TryParse

但是我有這樣的錯誤

A unique overload for method 'TryParse' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: Int64.TryParse(s: ReadOnlySpan<char>, result: byref<int64>) : bool, Int64.TryParse(s: string, result: byref<int64>)

System.Int32(64).TryParse是重載的方法。 因此,在您的代碼中,您必須明確指定要使用的方法的版本。

我認為您想解析一個字符串,因此代碼應為:

let tryParseInt32 : string -> int option    = tryParseWith System.Int32.TryParse
let tryParseInt64 : string -> int64 option  = tryParseWith System.Int64.TryParse

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM