.net - F#类型注释问题
问题描述
我是 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
推荐阅读
- javascript - 即使在建立连接后,Flask socketio 也没有收到来自 javascript 的任何消息
- azure - 使用 new-azwebapp 时如何选择运行时环境?
- flutter - Flutter 导航最佳实践
- sql - 将拆分的字符串放入每一行
- arrays - 从对象数组中删除 powershell 对象
- sql - 我们可以向表中的 SQL 查询返回的数据再添加一个值吗
- qt - 如何确保两种随机生成的颜色不相同?
- objective-c - 如何每天在两个不同的时间获得本地通知?
- solr - Solr 的标记关系索引性能
- elasticsearch - 我可以按公式对分组搜索结果进行排序吗?