I have to define the type profile of this function:
compose(f, g, x) = f(g(x))
The result should be the following, but I don't really get why.
(’a -> ’b) * (’c -> ’a) * ’c -> ’b
I have to define the type profile of this function:
compose(f, g, x) = f(g(x))
The result should be the following, but I don't really get why.
(’a -> ’b) * (’c -> ’a) * ’c -> ’b
If you look at compose
's definition, you first apply g
((’c -> ’a)
) to x, so you go from a 'c
to an 'a
. f
((’a -> ’b)
) then gets applied to said 'a
and returns a 'b
, hence the overall compose
function goes from 'c
to 'b
.
The reasoning goes pretty much the same as in your other question: How to define the type profile for this function?
a -> c -> e -> f
a = a -> b
and c = c -> d
) - signature (a -> b) -> (c -> d) -> e -> f
e = c
) - signature (a -> b) -> (c -> d) -> c -> f)
d = a
) - signature (a -> b) -> (c -> a) -> c -> f
f = b
) - signature (a -> b) -> (c -> a) -> c -> b
please try to provide some part of this reasoning on your own next time
EDIT: the above reasoning was the end for Haskell (with which the question was tagged in the beginning), for ML there is one more step:
*
between them instead of ->
, and the signature becomes (a -> b) * (c -> a) * c -> b