F# 方法定义语法

发布于 2024-07-24 00:14:28 字数 463 浏览 5 评论 0原文

我有一个方法(在本例中是静态的),但我不太清楚定义它的确切语法。

static member FindPath : Queue<Node> startNode : Node endNode : Node nodes : List<Node> = 
    //this method will call two other to be constructed methods and return a 
    //queue that is the return value of one of them
    return new Queue<Node>()

它在 startNode 和第一个节点之间的冒号上失败:

“标记类型中的语法错误”

制作这样的方法的最佳方法是什么?

I have a method (static in this case) and I can't quite figure out the exact syntax for defining it.

static member FindPath : Queue<Node> startNode : Node endNode : Node nodes : List<Node> = 
    //this method will call two other to be constructed methods and return a 
    //queue that is the return value of one of them
    return new Queue<Node>()

It fails on the colon between startNode and the first Node with:

"Syntax error in labelled type"

What would be the best way to make a method like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烏雲後面有陽光 2024-07-31 00:14:28
static member FindPath (startNode : Node)
                       (endNode : Node)
                       (nodes : List<Node>)
                     : Queue<Node>
   = new Queue<Node>()
static member FindPath (startNode : Node)
                       (endNode : Node)
                       (nodes : List<Node>)
                     : Queue<Node>
   = new Queue<Node>()
奈何桥上唱咆哮 2024-07-31 00:14:28

要使其成为多行,您只需在单独的行上进行调用

static member FindPath (startNode : Node) (endNode : Node) (nodes : List<Node>) = 
        let resultOfMethod1 = CallMethod1()
        CallMethod2()
        new Queue<Node>()

我还删除了返回类型,因为如果您返回这样的队列,则不需要它

To make it multiline you can just make the calls on separate lines

static member FindPath (startNode : Node) (endNode : Node) (nodes : List<Node>) = 
        let resultOfMethod1 = CallMethod1()
        CallMethod2()
        new Queue<Node>()

Also i removed the return type because you shouldn't need it if you return a queue like that

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文