The type of 5:

Prelude> :t 5
5 :: Num a => a

That's why it works.  The literal's type uses the type class.  Other fun stuff:

Prelude> :t "asdf"
"asdf" :: [Char]

Prelude> :set -XOverloadedStrings

Prelude> :t "asdf"
"asdf" :: Data.String.IsString a => a