这是F#中抽象成员的典型声明:
abstract member createEmployee : string -> string -> Employee
Run Code Online (Sandbox Code Playgroud)
您可以定义参数类型,但不能定义其名称.没有名称,在实现接口时如何判断每个参数是什么?换句话说,您如何知道接口是否希望实现为1-或2-?
1- member this.createEmployee firstName lastName = ...
2- member this.createEmployee lastName firstName = ...
Run Code Online (Sandbox Code Playgroud)
我是从错误的角度看待问题(习惯于C#)吗?
Ram*_*nir 39
关于什么:
abstract member createEmployee : firstName:string -> lastName:string -> Employee
Run Code Online (Sandbox Code Playgroud)
?
这个语法非常适合IMO.我想用参数作为元组(比如C#方法)这样做,并且只有通过反复试验我才发现这个工作:
abstract member PutChar : x:int * y:int * c:char * flag:Background -> unit
Run Code Online (Sandbox Code Playgroud)
这个丑陋的变体也有效:
abstract member PutChar : x : int * y : int * c : char * flag : Background -> unit
Run Code Online (Sandbox Code Playgroud)
以下是所有感觉合理但失败并出现同样错误的事情 - Unexpected symbol ':' in member definition.:
// ALL BAD vvv
abstract member PutChar : (x:int * y:int * c:char * flag:Background) -> unit
abstract member PutChar : (x:int, y:int, c:char, flag:Background) -> unit
abstract member PutChar : (x:int) * (y:int) * (c:char) * (flag:Background) -> unit
// ALL BAD ^^^
Run Code Online (Sandbox Code Playgroud)