I am trying to understand Haskell type variables for functions. I wrote a function:
applyTwice f x = f(f x)
I tried to understand the type variables for this function, so I did a :t applyTwice. This is how Haskell interprets the types:
applyTwice :: (t -> t) -> t -> t
Then I created another function:
applyOnce f x = f x
This time for :t Haskell returns
applyOnce :: (t1 -> t) -> t1 -> t
My questions are
How do we read/understand what these functions take and return?
This is for
applyTwice. If they say anything left side of the->is what the function takes and right hand side is what it returns then should it not beapplyTwice :: ((t -> t) -> t) -> t?(t -> t)for(f x)and((t -> t) -> t)forf (f x)and the return type beingt.- This is for
applyOnce. Why is the function's type interpreted asapplyOnce :: (t1 -> t) -> t1 -> t? because we only take a function and return it's value. Should it not beapplyOnce :: (t1 -> t) -> t1?
As a beginner in Haskell I would like any advice in this.