【发布时间】:2013-04-18 05:22:25
【问题描述】:
我正在尝试使用 F# 签名文件为轻量级数据存储模块创建抽象。这是我的签名文件代码,假设它被称为repository.fsi
namespace DataStorage
/// <summary>Lightweight Repository Abstraction</summary>
module Repository =
/// <summary> Insert data into the repository </summary>
val put: 'a -> unit
/// <summary> Fetch data from the repository </summary>
val fetch: 'a -> 'b
/// <summary> Remove data from the repository </summary>
val remove: 'a -> unit
这里是对应的实现,我们称之为repository.fs
namespace DataStorage
module Repository =
(* Put a document into a database collection *)
let put entity = ()
(* Select a document from a database collection *)
let fetch key = ("key",5)
(* Remove a document from a database collection *)
let remove entity = ()
在我的 Visual Studio 项目文件中,我有上面的签名文件 (repository.fsi) 我的实现文件(repository.fs)。 put 和 remove 函数正在被正确解析和验证,没有错误(在实现文件中),但 fetch 函数一直给我红色在 Visual Studio 中波浪形地显示以下错误消息:
模块“DataStorage.Repository”包含
val fetch: s:string -> string * int
但它的签名指定
val fetch<'a,'b> : 'a -> 'b
各自的类型参数计数不同
谁能告诉我我做错了什么?我的 fetch 函数值是否定义错误 我的签名文件?我只是想在我的签名文件中创建一个通用函数('a -> 'b),并让实现将一种类型作为输入并返回另一种类型作为输出。
【问题讨论】:
-
fetch的签名是通用的,但实现不是。如果实现只是一个存根,请尝试将其替换为let fetch key = Unchecked.defaultof<_>以使其能够编译。 -
感谢@Daniel 的回答,我试试看。
标签: f# signature-files