RCIX
RCIX

Reputation: 39427

F# Method Definition Syntax

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?

Upvotes: 1

Views: 439

Answers (2)

Jake
Jake

Reputation: 3457

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

Upvotes: 5

Ganesh Sittampalam
Ganesh Sittampalam

Reputation: 29100

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

Upvotes: 3

Related Questions