.net - Trouble with a member constraint invocation expression when the member signature has type variables in F# -


i'm having trouble using member constraint invocation expressions when member signature has type variables. specifically, code

[<autoopen>] module foo  // preapplied lens type lens <'i,'j> = { : 'j; set : 'j -> 'i }  // record type lenses  type foo1 = {     num_ : int;     letter_ : char }     member this.num = {         = this.num_;         set = (fun num' -> {this num_=num'})}     member this.letter = {         = this.letter_;         set = (fun letter' -> {this letter_=letter'})} end  let (foo1:foo1) = {num_ = 1; letter_ = 'a'}  // ecord type lenses  type foo2 = {     num_ : int;     name_ : string }     member this.num = {         = this.num_;         set = (fun num' -> {this num_=num'})}     member this.name = {         = this.name_;         set = (fun name' -> {this name_=name'})} end  let (foo2:foo2) = {num_ = 2; name_ = "bob"}  // add 2 record num lens let inline add2 (x : ^t) =     let num = (^t : (member num : lens<^t,int>) (x)) in     num.get + 2 

gives error:

test05.fsx(39,47): error fs0010: unexpected symbol ) in expression

the issue @ member constraint invocation expression on second last line. basically, can't figure out how pass type variables ^t , int lens type within member constraint invocation expression. there way accomplish this?

there must space between < , ^ in static constraint:

// add 2 record num lens let inline add2 (x : ^t) =     let num = (^t : (member num : lens< ^t,int>) (x)) in     num.get + 2 

otherwise, both characters <^ treated name of infix function (aka "operator").


Popular posts from this blog