Pages

Saturday, June 9, 2012

SelfNote: inline is the way to get out of the generic error


if you ever have some error like:


This code is not sufficiently generic. The type variable  ^a when  ^a : not struct and  ^a : (new : unit ->   ^a) and  ^a : (member get_Value :  ^a -> string) and  ^a : (member set_Value :  ^a * string -> unit) could not be generalized because it would escape its scope.       


in the code:



let get_enum_obj<'a  when 'a : not struct
                     and  'a: (new : unit->'a)
                     and  'a: (member Value:string)
                     and  'a: (member Value:string with set)>  (db:Table<'a>) s =  

the magic word is to use "inline" in the function. 

No comments: