What's the meaning of the `in` keyword in this example (F#)
f#, keyword
Solution
The `let x = ... in expr` allows you to declare a binding for some variable `x` which can then be used in expr.
In this case `p` is a function which takes an argument `stream` and then returns either `Success` or `Failure` depending on the result of the match, and this function is returned by the `CharParser` function.
The F# light syntax automatically nests `let .. in` bindings, so for example
let x = 1
let y = x + 2
y * z
is the same as
let x = 1 in
let y = x + 2 in
y * z
Therefore, the `in` is not needed here and the function could have been written simply as
let CharParser (c: char) : Parser<char> =
let p stream =
match stream with
| x::xs when x = c -> Success(x, xs)
| _ -> Failure
p
Problem
I've been trying to get my head round various bits of F# (I'm coming from more of a C# background), and parsers interest me, so I jumped at this blog post about F# parser combinators: http://santialbo.com/blog/2013/03/24/introduction-to-parser-combinators One of the samples here was this: ``` /// If the stream starts with c, returns Success, otherwise returns Failure let CharParser (c: char) : Parser<char> = let p stream = match stream with | x::xs when x = c -> Success(x, xs) | _ -> Failure in p //what does this mean? ``` However, one of the things that confused me about this code was the `in p` statement. I looked up the `in` keyword in the MSDN docs: http://msdn.microsoft.com/en-us/library/dd233249.aspx I also spotted this earlier question: Meaning of keyword "in" in F# Neither of those seemed to be the same usage. The only thing that seems to fit is that this is a pipelining construct.