Why do I need annotation here?
In the following code:
type ParseResult<'a> =
{
Result : Option<'a>;
Rest : string
}
type Parser<'a> = string -> ParseResult<'a>
let ThenBind p (f : Option<'a> -> Parser<'b>) : Parser<'b> =
fun input ->
let r = p input
match r.Result with
| None -> { Result = None; Rest = input }
| _ -> (f r.Result) r.Rest
With type annotation for f, the type for ThenBind is:
p:(string -> ParseResult<'a>) ->
f:(Option<'a> -> Parser<'b>) ->
input:string -> ParseResult<'b>
But without annotation, this:
p:(string -> ParseResult<'a>) ->
f:(Option<'a> -> string -> ParseResult<'b>) ->
input:string -> ParseResult<'b>
Why?
+3
source to share