如何在F#模块中定义可选参数? [英] How to define optional parameters in F# modules?
问题描述
我试图用F#重写一个小的C#库,但遇到错误.我正在尝试为模块中的方法定义可选参数,但是编译器会说仅在类型成员上允许使用可选参数".
I'm trying to re-write a tiny C# lib in F# and I've encountered an error. I'm trying to define optional parameters for a method in a module but the compiler says "Optional arguments are only permitted on type members".
我已经检查了为什么不能在松散的函数中使用它们,但是在键入static member
或member
时,我会收到另一个错误. /p>
I've checked why you can't use them in loose functions but when typing static member
or member
I get another error instead.
module Kingdom =
let Rule (?years : int) =
()
在阅读推荐答案
通过使用另一种方法来定义静态您可以在其中添加 By using another way to define the "static class" you can add 这篇关于如何在F#模块中定义可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!member
.然后,您可以使用可选参数.member
to it. And then you can use optional parameters.[<AbstractClass; Sealed>]
type Kingdom private () =
static member Rule (?years : int) = ()