I am struggling to understand function within function signature types in Haskell, I have seen this function;
twice :: (a -> a) -> a -> a
twice f x = f(f x)
Which does twice the chosen function on a parameter. I understand f is a function however do not understand why we have the signature type (a -> a) -> a -> a
I thought it would be (a -> b) -> a -> b
because
- You provide a as a parameter so the input of the function must accept the type of a.
- b is the output type of the function so the overall output type is of type b.
I am new to Haskell :)
a -> b
you could not apply the function for a second time, because after the first time you will have typeb
, but your function only takesa
as an input arg – behzad.nouri