This question is based on an exercise question in the book "Haskell Programming from first principles". It's for helping us understand parametricity.
How do we get type signature a -> a -> a
? The book states that there are only 2 type signatures that work.
I've tried these, but they all failed:
test1 a a = a
ERROR - Repeated variable "a" in pattern
test1 = \ a -> a -> a
ERROR - Syntax error in input (unexpected `->')
test1 _ a = id a
wrong result: test1 :: a -> b -> b
test1 a = id a . id a
wrong result: test1 :: (a -> a) -> a -> a
test1 a b = a + b
wrong result due to the Num
type constructor: test1 :: Num a => a -> a -> a