\a -> map ($ a) definitely fine, but maybe even better - Applicative : yes
<**> :: Applicative f => fa -> f (a -> b) -> fb
which has an instance <*> :: [a] -> [a->b] -> [b] . Very similar to what you want! You just need to put your value a in a singleton list, for which there is also a dedicated function in Applicative : pure .
apply :: Applicative f => a -> f (a -> b) -> fb apply = (<**>) . pure
Although in reality I would prefer to restrict the signature a -> [a->b] -> [b] for this top-level binding, since Applicative pretends that you have the most common signature, which it is not:
apply :: Functor f => a -> f (a -> b) -> fb apply a = fmap ($ a)
Indeed, my solution is probably best when you are in some kind of pipeline, I believe that it is better not to define apply , but to use (<**>) . pure (<**>) . pure directly in the code.
source share