concept inc in category haskell

appears as: inc
Get Programming with Haskell

This is an excerpt from Manning's book Get Programming with Haskell.

You can see the difference if you try inc and succ on the maxBound of Int:

GHCi> inc maxBound :: Int
-9223372036854775808
GHCi> succ maxBound :: Int
*** Exception: Prelude.Enum.succ{Int}: tried to take 'succ' of maxBound

Because there’s no true successor to a Bounded type, succ throws an error. The inc function just rotates you back to the beginning.

You’ve written the function inc to increment a value a few times as a sample function. But how can you write an incrementing function that works with the wide range of possible numbers you’ve seen? Frustratingly enough, in unit 1, without specifying types, you could do this. How can you write the type signature of an inc function that works on all numbers?

One type class we didn’t discuss is Enum. Use :info to look at the definition of this type class, as well as example members. Now consider Int, which is an instance of both Enum and Bounded. Given the following definition of inc:

inc :: Int -> Int
inc x = x + 1

and the succ function required by Enum, what’s the difference between inc and succ for Int?