如果我有一个包含所有像这样的数据库函数的记录类型
type Database =
{ getThingsByCountThenLength: int -> int -> Thing list
getUsersByFirstNameThenLastName: string -> string -> User list }
有什么方法可以命名输入参数,这样更清楚吗?类似于以下内容(无法编译)
type Database =
{ getThings: count:int -> length:int -> Thing list
getUsers: firstName:string -> lastName:string -> User list }
(请注意,它确实适用于接口;我只希望它用于记录。)
type IDatabase =
abstract getThings: count:int -> length:int -> Thing list
abstract getUsers: firstName:string -> lastName:string -> User list
这不是一个直接的答案(我认为没有答案),但是作为替代方案,您可以使用单格联合类型,这不仅可以增加清晰度并继续允许使用柯里化,而且还可以保证编译时的正确性。
type Count = Count of int
type Length = Length of int
type FirstName = FirstName of string
type LastName = LastName of string
type Database =
{ getThings: Count -> Length -> Thing list
getUsers: FirstName -> LastName -> User list }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句