f# - Why do I need a type annotation here? -


in 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         | none -> { result = none; rest = input }         | _ -> (f r.result) r.rest 

with type annotation f, type thenbind is:

p:(string -> parseresult<'a>) -> f:(option<'a> -> parser<'b>) -> input:string -> parseresult<'b> 

but without annotation, it's:

p:(string -> parseresult<'a>) -> f:(option<'a> -> string -> parseresult<'b>) -> input:string -> parseresult<'b> 

why?

you don't need type annotation. 2 types identical.

parser<'a> alias string -> parseresult<'a>, makes no difference whether result type of f declared parser<'b> or string -> parseresult<'b>. they're exact same type.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -