love-haskell / coercible-utils

Utility functions for Coercible types
https://hackage.haskell.org/package/coercible-utils
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

Figure out the performance implications of using (#.) or (.#) vs. (.) #11

Open sjakobi opened 6 years ago

sjakobi commented 6 years ago

This seems to be the main selling point of the operators.

We should add some benchmarks and summarize the results in the docs.

treeowl commented 4 years ago

Generally speaking, they're helpful in in higher-order contexts when there might not be enough inlining to avoid problems. f . coerce or coerce . f can potentially build a closure that just passes an argument to f, while coerce #. f and f .# coerce are really just f. The reason is that if GHC can't see that f has arity at least 1, then f and the dotted version could actually be different. This tends only to be a problem when f is totally unknown and the HOF doesn't inline. So it usually won't matter, but sometimes can.