In the f # project, I have the following types:
type A = { Name: string } type B = { Name: string; SurName: string } type C = { Name: string; SurName: string; MaidenName: string }
and the following function that uses a constraint on a common argument:
let inline filterByName<'a when 'a: (member Name: string)> (name: string) (collection: 'a seq) = collection |> Seq.where(fun i -> i.Name = name)
The problem is that I get the following compile time error:
Limit type mismatch. A type
'a
incompatible with type
WITH
Type '' a 'does not match type' C '
Removing inline from the function definition gives me the following compile-time error:
This code is not general enough. a variable of type ^ a when ^ a: (member get_Name: ^ a → string) cannot be generalized, since it will avoid its capabilities.
What I'm trying to achieve is a function that in this case uses a common type with the property of a specific name, "Name". What am I doing wrong or what am I missing?
source share