本文介绍了如何在F#模块中定义可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用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) = ()在阅读有关此文档的Microsoft文档.
推荐答案通过使用另一种方法来定义静态您可以在其中添加member.然后,您可以使用可选参数.
By using another way to define the "static class" you can add member to it. And then you can use optional parameters.
[<AbstractClass; Sealed>] type Kingdom private () = static member Rule (?years : int) = ()更多推荐
如何在F#模块中定义可选参数?
发布评论