Ok, I have a List of functions in F#, and for claritry i want to spread them over multiple lines, as shown:
type pos=char*int
let potentialPoss:List<pos->pos>=
[fun (c,i)->(c+char 1,i+2);
fun (c,i)->(c+char -1,i+2);
fun (c,i)->(c+char 1,i-2);
fun (c,i)->(c+char -1,i-2);
fun (c,i)->(c+char 2,i+1);
fun (c,i)->(c+char -2,i+1);
fun (c,i)->(c+char 2,i-1);
fun (c,i)->(c+char -2,i-2) ]
Seems reasonable enough right? (FYI, pos stores the algebracic position of a chess piece, and potentialPoss is a list of knights moves)
But I get a syntax on the second fun :"Unexpected keyword 'fun' in expression. Expected ']' or other token." and on the [: "Unmatched '['."
this feels like hte right syntax to me? any sugestions?
You just need all the list elements to be as indented as the first element:
[fun (c,i)->(c+char 1,i+2);
fun (c,i)->(c+char -1,i+2);
fun (c,i)->(c+char 1,i-2);
etc
This is true for all blocks of code (computation expressions, pattern matching, etc).
I'm not sure why the compiler barfs on this, but this fixes it:
type pos=char*int
let potentialPoss:List<pos->pos>=
[
fun (c,i)->(c+char 1,i+2)
fun (c,i)->(c+char -1,i+2)
fun (c,i)->(c+char 1,i-2)
fun (c,i)->(c+char -1,i-2)
fun (c,i)->(c+char 2,i+1)
fun (c,i)->(c+char -2,i+1)
fun (c,i)->(c+char 2,i-1)
fun (c,i)->(c+char -2,i-2)
]
Incidentally, semicolons are generally interchangeable with line breaks in F#, so I removed them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With