DEV Community

Discussion on: F# : using List.exists on record types may cause breaking changes

Collapse
 
armousness profile image
Sean Williams

I think this is a—not exactly a bug, but an inadequacy of the type inference system. Other things that would fix your problem are,

let example1 = List.exists (fun (i: Person) -> i.name = "X") people

let inline list_exists c f = List.exists f c
let example2 = list_exists people (fun i -> i.name = "X")
Enter fullscreen mode Exit fullscreen mode

It seems that F# type inference works from left-to-right. I appreciate that type inference is more ambiguous in an object-oriented language for precisely the reason you laid out, that classes and records are namespaces so properties and methods don't uniquely identify types. But the big mistake of F# is, when you're dealing in combinators like map and filter and exists, the type inference works if you put the collection first (since it's unambiguously typed in almost all cases). So why did they put the functional argument first?