Applying a list of functions in Haskell

后端 未结 3 1065
遥遥无期
遥遥无期 2021-01-13 04:43

I wrote a function that applies a list of functions to an item.

applyAll :: [a -> b] -> a -> [b]
applyAll [] _ = []
applyAll (f:fs) x = (f x) : (a         


        
3条回答
  •  心在旅途
    2021-01-13 05:35

    You could use:

     applyAll l v = fmap ($ v) l
    

    fmap lifts a function over the input list (actually any Functor). $ has type (a -> b) -> a -> b so it applies a function to a given value. ($ v) is a section which applies the given function to v.

提交回复
热议问题