0

So I am doing some exercised in Haskell and I thought the type of int2nat in

int2nat :: (Eq t, Num t) => t -> Nat

int2nat 0 = Zero
int2nat n = Succ (int2nat (n-1)

would be int2nat :: (Num t) => t -> Nat.

Can somebody explain why this is not the case and why the additional Eq t is correct instead?

Zeta
  • 103,620
  • 13
  • 194
  • 236
  • Welcome to StackOverflow. Please always use code instead of pictures of code in your questions, as it makes it easier for others to read and test your code. – Zeta Jan 01 '22 at 19:36

1 Answers1

1

Because you matched on the numeric literal 0 in the pattern. int2nat 0 = Zero desugars to something like int2nat n | n == fromInteger 0 = Zero.