Re:Object Oriented Programming is Inherently Harmful
by seanmcdirmid on Sunday November 30, 2014 @07:45PM
(#8678942)
I doubt that was what was going on, but I can't find any documentation right now on how F# optimizes case matches. If it was doing that, it would have to apply those classes to all instances of the patterns, which seems unlikely in the face of separate compilation as "Foo of int * bool * string" could be constructed in a far away place. Well, if Foo was a local type that wouldn't escape, perhaps they could optimize it in the module, but it still seems unlikely.
OO languages have trouble optimizing constructs such as interfaces (and other forms of multiple inheritance) because the v-table is no longer very linear. Now throw in arbitrary predicates and you are pretty much back to linear search. Probably the state of the art can be found in GHC, but even they probably fall back to linear in a lot of cases.
Re:Object Oriented Programming is Inherently Harmful
by noblethrasher on Sunday November 30, 2014 @08:02PM
(#8678976)
Looks like you're correct; I just examined some F# code in LINQPad 4, and the IL has a bunch of `isinst` instructions to check the type at runtime, and no `callvirts` to the one pattern matching expression that I created.
It may not work for all kinds of pattern matching, but that seems like the most straightforward way of handling sum types. What am I missing?