I defined an identity function and a composition function:
def identity[T](x: T): T = x
def composition[A, B, C](f: A => B, g: B => C)(x: A) = g(f(x))
I am trying to argue that the identity function can be applied on both sides with the same result:
assert(composition((x: Int) => x + 1, identity)(3) == composition(identity, (x: Int) => x + 1)(3))
However, I get the following errors:
Error:(7, 40) type mismatch;
found : Nothing => Nothing
required: Int => Nothing
assert(composition((x: Int) => x + 1, identity)(3) == composition(identity, (x: Int) => x + 1)(3));}
and
Error:(7, 68) type mismatch;
found : Nothing => Nothing
required: A => Nothing
assert(composition((x: Int) => x + 1, identity)(3) == composition(identity, (x: Int) => x + 1)(3));}
Why is this so?
source
share