views:

215

answers:

2

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?

+3  A: 
static member FindPath (startNode : Node)
                       (endNode : Node)
                       (nodes : List<Node>)
                     : Queue<Node>
   = new Queue<Node>()
Ganesh Sittampalam
the problem then becomes what is the syntax for defining a multiline method like that?
RCIX
In F# it's all about indentation. I've noticed it's not the first time you ask about multiline. Just indent the body 4 spaces (in VS you can just use one tab) compared to the method definition indentation and write the body. When the method finishes, just remove the last level of indentation
emaster70
+5  A: 

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

Cipher
so if the return type of CallMethod2 is a Queue of Nodes then it will automatically return that? BTW i would acccept both but SO doesnt allow that sorry.
RCIX
Yes, the last expression of the method is the one returned. No 'return' keyword is needed.
Nathan Sanders
OK cool thanks.
RCIX
F# does some real magic when it comes to infering the types of parameters. I bet if FindPath used startNode, endNode, and nodes only with functions that take a Node or Node list as the case may be, that you could remove ALL the type annotations on FindPath's declaration.
James Hugard