haskell - Are there any use cases for this function : foo :: (b -> c) -> (a -> b) -> (a -> c) -
for function :
foo :: (b -> c) -> (a -> b) -> (a -> c)
taken http://www.seas.upenn.edu/~cis194/spring13/lectures/04-higher-order.html
is function no practical use ? (b -> c)
cannot constructed unless type c input parameter within function ?
and same (a -> b) -> (a -> c)
: b & c not input parameters these functions.
are there use cases function ?
if question using function composition in practice, here small example. let's assume want write function sum of squares of elements of list of numbers. how that? well, write like: squaresum xs = sum (map (^2)) xs
. can use function composition instead: squaresum = sum . map (^2)
(i use .
function composition here instead of foo
, doesn't matter). example shows function obtained using function composition(it practical @ least in sense compiles , works correctly). benefits of function composition become more obvious when need compose multiple functions(possibly partially applied).
Comments
Post a Comment