No argument names in abstract declaration?

亡梦爱人 提交于 2019-12-03 15:54:01

问题


This is the typical declaration of an abstract member in F#:

abstract member createEmployee : string -> string -> Employee

You define the argument types but not their names. Without names, how do you tell what each parameter is when you implement the interface? In other words, how do you know if the interface expects to be implemented as 1- or 2-?

1-   member this.createEmployee firstName lastName = ...
2-   member this.createEmployee lastName firstName = ...

Am I looking the problem from a wrong perspective (being used to C#)?


回答1:


What about:

abstract member createEmployee : firstName:string -> lastName:string -> Employee

?




回答2:


The syntax for this is super fiddly IMO. I wanted to do this with the parameters as a tuple (like a C# method) and only through trial and error did I find this to work:

    abstract member PutChar : x:int * y:int * c:char * flag:Background -> unit

And this uglier variant also works:

    abstract member PutChar : x : int * y : int * c : char * flag : Background -> unit

Below are things that all felt reasonable but failed with the same error - 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 ^^^


来源:https://stackoverflow.com/questions/7487551/no-argument-names-in-abstract-declaration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!