Instead of fmap, which applies a function to a value-in-a-functor:
fmap :: Functor f => (a -> b) -> f a -> f b
I needed a function where the functor has a function and the value is plain:
thing :: Functor f => f (a -> b) -> a -> f b
but I can’t find one.
What is this pattern called, where I apply a function-in-a-functor (or in an applicative, or in a monad) to a plain value?
I’ve implemented it already, I just don’t quite understand what I did and why there wasn’t already such a function in the standard libraries.
You don’t need
Applicativefor this;Functorwill do just fine:Interestingly,
applyis actually a generalisation offlip; lambdabot replacesflipwith this definition as one of its generalisations of standard Haskell, so that’s a possible name, although a confusing one.By the way, it’s often worth trying Hayoo (which searches the entirety of Hackage, unlike Hoogle) to see what names a function is often given, and whether it’s in any generic package. Searching for
f (a -> b) -> a -> f b, it findsflip(inData.Functor.Syntax, from thefunctorspackage) and($#)(from thesynthesizerpackage) as possible names. Still, I’d probably just usefmap ($ arg) fat the use site.