gpt4 book ai didi

f# - 有没有办法在 F# 构造函数中为函数指定命名参数?

转载 作者:行者123 更新时间:2023-12-04 21:10:21 25 4
gpt4 key购买 nike

有没有办法在构造函数中命名函数参数?

type UnnamedInCtor(foo: string -> string -> bool) = 
member this.Foo: string -> string -> bool = foo
member this.Bar: a:string -> b:string -> bool = foo
member this.Fizz = foo

//Does not compile
type NamedInCtor(foo: a:string -> b:string -> bool) =
member this.Foo: string -> string -> bool = foo
member this.Bar: a:string -> b:string -> bool = foo
member this.Fizz = foo

最佳答案

我认为在 F# 中这是不可能的,但是您可以使用 type abbreviations如果你想记录 foo 代表什么:

// Compiles
type aToBToC = string -> string -> bool
type NamedInCtor(foo: aToBToC) =
member this.Foo: string -> string -> bool = foo
member this.Bar: a:string -> b:string -> bool = foo
member this.Fizz = foo

关于f# - 有没有办法在 F# 构造函数中为函数指定命名参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36165981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com