0

Learning Haskell right now and stumbled upon this oddity. Consider:

main = do
    print $ mysquare 2
    print $ mysquare 2.0

Output with

-- style A:
mysquare x = x * x

is 4 and 4.0. Likewise, output with

-- style B:
mysquare x = x ^ 2

is 4 and 4.0. But output with

-- style C:
mysquare = (^2)

is 4.0 and 4.0.

I wouldn't have expected from my beginner understanding so far that η-reducing style B into style C would silently change the Int into a Fractional. Why does that occur?

metaleap
  • 2,132
  • 2
  • 22
  • 40

0 Answers0