Question

I am wondering for a while now what is f. Could someone provide an example to how I should be running this function? (Note: I understand that the (.) is function composition and I know what function composition if)

-- compose a function n >= 0 times with itself
composeN :: Int -> (a -> a) -> (a -> a)
composeN 0 f = id
composeN n f = f . (composeN (n-1) f)
Was it helpful?

Solution

f is an arbitrary function, provided by the user. I could supply composeN with succ, to increment an integer, and have it be composed three times and applied to 2, thereby adding 3:

ghci> composeN 3 succ 2
5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top