(<*>) apply vs. ($) apply

The multiple definitions of apply can be pretty confusing for beginners (at least it was for me), and now it’s a bit awkward when referring to apply in documentation, since I feel like additional clarification is often needed.

Control.Apply
apply :: forall f a b. Apply f => f (a -> b) -> f a -> f b
<*>
Data.Function
apply :: forall a b. (a -> b) -> a -> b
$

It also seems like it would be easier to remember the infix notation if <*> was swapped with map's <$>, although that would be a departure from Haskell. I guess Haskell doesn’t have this issue with overlapping function names, since it just defines these infix operators without a named function.

One way to add clarity is to rename $'s apply to something like noParens. It seems like only the infix operator is used (and exported by Prelude), so changing the underlying function name wouldn’t be too annoying of a breaking change.

1 Like

I think it’s hard to justify a breaking change like this. I’d recommend referring to $ using the symbol rather than the name apply in documentation to avoid this confusion; I’m not sure I’ve ever seen people referring to $ using the name “apply”.

…but by the same token, if no-one is using the underlying function name for ($) it’s not that bad a breaking change to consider at some point.

I can’t imagine why or how anyone ever would use the function by name, has it ever been seen in the wild?

It’s in Prelude, so you have to be pessimistic. There probably are cases of people referring to it by name in code; I just haven’t seen it in any documentation or learning resources.