[Haskell-beginners] arrow type signature question
Daniel Fischer
daniel.is.fischer at web.de
Thu Nov 18 13:29:32 EST 2010
On Thursday 18 November 2010 18:51:32, MH wrote:
> Oh, so this signature is really a partial application that expects
> another parameter to be executed.
Depends on how you look at it.
Strictly speaking, there is no such thing as partial application. Every
function takes exactly one argument, so it's either not applied to any
argument at all yet or it's fully applied. But the result of a function
application can be another function, so it may take another argument ...
However, always talking about functions taking an argument of type a and
returning a function taking an argument of type b and returning a function
taking an argument of type c ...
is terribly cumbersome, so we speak of functions taking several arguments.
But note that the number of arguments a function takes until the final
result is no longer a function is not always fixed. For example,
id :: a -> a takes one argument, obviously, doesn't it?
But if that argument is a function, it takes one more argument, so id can
take two arguments, or three, or however many you want, it depends on which
arguments you pass.
So when you have a value of type a -> b -> c (which is the same as
a -> (b -> c), since the function arrow is right-associative), and apply it
to a value of type a, sometimes it is more appropriate to think of that as
a partial application, sometimes as a complete application resulting in a
function.
> So
> resultFun :: (h b -> h b') -> (h (a->b) -> h (a->b'))
which is
resultFun :: (h b -> h b') -> h (a -> b) -> h (a -> b')
> is
> foo :: h b -> h b'
Yes
> bar :: h (a->b) -> h (a->b')
No. bar :: h (a -> b)
resultFun foo :: h (a -> b) -> h (a -> b')
so it takes an argument of type h (a -> b) and its result has type
h (a -> b')
(which may be another function type, if h x = e -> x).
>
> firstFunction = resultFun foo
> result = firstFunction bar
Yep
>
> Is this correct?
More information about the Beginners
mailing list