Haskell, warum erfordert "Num x" "Show x"?

Kürzlich habe ich mir Haskell mit angeschautLYAH.

Ich habe mit Typenklassen rumgespielt und diese schnelle Testfunktion geschrieben:

foo :: (Num x) => x -> String
foo x = show x ++ "!"

Aber das erzeugt diesen Fehler:

test.hs:2:9:
    Could not deduce (Show x) arising from a use of `show'
    from the context (Num x)
    bound by the type signature for foo :: Num x => x -> String
    at test.hs:1:8-29
    Possible fix:
      add (Show x) to the context of
        the type signature for foo :: Num x => x -> String

Aber laut LYAH:

Um Num beizutreten, muss ein Typ bereits mit Show und Gl.

Also wenn alles drin istNum ist eine Teilmenge vonShow undEqWarum muss ich die Typensignatur in ändern?foo :: (Num x, Show x) => x -> String damit das klappt? Sollte es nicht möglich sein zu schließen, dass aNum ist das auch darstellbar?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage