我是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>)
答案 0 :(得分:2)
System.Int32(64).TryParse
是重载方法。因此,在您的代码中,您必须明确指定要使用的方法的版本。
我认为您想解析一个字符串,因此代码应为:
let tryParseInt32 : string -> int option = tryParseWith System.Int32.TryParse
let tryParseInt64 : string -> int64 option = tryParseWith System.Int64.TryParse