【发布时间】:2013-01-13 15:57:20
【问题描述】:
我有一个令人烦恼的错误。
type Animal =
abstract member Name : string
type Dog (name : string) =
interface Animal with
member this.Name : string =
name
let pluto = new Dog("Pluto")
let name = pluto.Name
最后一行,特别是“名称”会生成一个编译器错误,指出“未定义字段、构造函数或成员‘名称’”。
我使用的解决方法是写
let name = (pluto :> Animal).Name
但是,这很烦人,并且会产生很多视觉噪音。在 F# 中是否可以在不明确告诉编译器 Name 是 Animal 类型的派生成员的情况下解析 Name ?
【问题讨论】:
标签: interface f# overloading overload-resolution explicit-interface