如何在F#模块中定义可选参数?

编程入门 行业动态 更新时间:2024-10-19 20:41:46
本文介绍了如何在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#模块中定义可选参数?

本文发布于:2023-11-10 02:37:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可选   模块   定义   参数   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!