-2

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
dfeuer
  • 48,079
  • 5
  • 63
  • 167
mlhack
  • 73
  • 1
  • 4

2 Answers2

0

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.

Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
0

The reasoning goes pretty much the same as in your other question: How to define the type profile for this function?

  1. 3 arguments - signature a -> c -> e -> f
  2. first two are unary functions (a = a -> b and c = c -> d) - signature (a -> b) -> (c -> d) -> e -> f
  3. third is argument to second function (e = c) - signature (a -> b) -> (c -> d) -> c -> f)
  4. result of second function is argument to first one (d = a) - signature (a -> b) -> (c -> a) -> c -> f
  5. output of first function is output of whole expression (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:

  1. First three are tuple argument, thus * between them instead of ->, and the signature becomes (a -> b) * (c -> a) * c -> b
Community
  • 1
  • 1
Tomasz Lewowski
  • 1,935
  • 21
  • 29