<div dir="ltr">What would be an elegant way of writing this<div><br></div><div>computeHead :: (a -> [b]) -> [a] -> [b]</div><div><br></div><div>Where when [a] is null, it returns a null list, but when [a] contains one or more elements, it applies the given function to the head of a and returns that? Is there some existing typeclass operator that facilitates this?</div><div><br></div><div>You can write</div><div><br></div><div>computeHead _ [] = []</div><div>computeHead f (x:_) = f x</div><div><br></div><div>But that first line seems suspicious to me... it makes me think about how in the list Monad, an empty list falls through. But I can't quite make it work. </div></div>