F#否认存在构造函数(可能与类型约束相关)

时间:2014-03-24 00:03:42

标签: f# signature-files

在下面的代码中,F sharp说:模块xyz需要值new : (IBlah<'a> * 'b) -> test<'a, 'b>')

我已经尝试提供那个确切的构造函数作为一个显式的新的但它似乎没有帮助,尽管Intellisense虽然类型是相同的。我希望我能以某种方式得到错误的约束。有人可以告诉我要改变什么,以便代码编译(不删除约束)?非常感谢。

首先是fsi文件:

module xyz

type IBlah<'a> =
    abstract something : 'a -> 'a

type IHuha =
    abstract something : unit -> unit

type test<'a, 'b when 'a :> IHuha and 'b : comparison> =
    new : (IBlah<'a> * 'b) -> test<'a, 'b>
    member huha : unit -> unit

fs文件是:

module xyz

type IBlah<'a> =
    abstract something : 'a -> 'a

type IHuha =
    abstract something : unit -> unit

type test<'a, 'b when 'a :> IHuha and 'b : comparison> (x:IBlah<'a>, y:'b) =

    member x.huha () = printf "%O" x

1 个答案:

答案 0 :(得分:3)

问题是签名文件正在描述一个构造函数,它接受一个类型为tuple

的值
(IBlah<'a> * 'b)

实际的构造函数虽然采用了IBlah<'a>'b类型的2个值。推测.fs实现是你想要的。如果是这样,那么只需从.fsi文件中删除额外的parens

new : IBlah<'a> * 'b -> test<'a, 'b>
相关问题