F# 签名文件中具有接口的联合类型
在实现文件中给定以下代码:F# 签名文件中具有接口的联合类型,f#,signature,f#-3.0,F#,Signature,F# 3.0,在实现文件中给定以下代码: namespace Lib module Test = type ITest = abstract member IsTest: bool type T = Test with interface ITest with member this.IsTest = true let create () = Test 以及以下签名文件: namespace Lib module T
namespace Lib
module Test =
type ITest =
abstract member IsTest: bool
type T = Test with
interface ITest with
member this.IsTest = true
let create () = Test
以及以下签名文件:
namespace Lib
module Test =
[<Interface>]
type ITest =
abstract member IsTest: bool
type T
val create: unit -> T
名称空间库
模块测试=
[]
型式试验=
抽象成员IsTest:bool
T型
val创建:单位->T
出现以下警告:
警告2。该类型实现了接口“Test.ITest”,但签名未显示该接口。您应该在签名中列出接口,因为通过动态类型转换和/或反射可以发现接口
应如何在签名文件中更改类型T的签名以符合实现?您应在模块签名(fsi)文件内的类型定义中列出接口,例如:
namespace Lib
module Test =
[<Interface>]
type ITest =
abstract member IsTest: bool
type T =
interface ITest
//you can list other interfaces here
val create: unit -> T
使用
如果您计划升级到F#4+,则必须像原来的示例中那样进行更改。编译器将显示此更改的相关警告
type T = ...
type T with ...