[haskell][hugs][どうでもいいこと] Tuple が show できるのは 5 つまで
UUAG で遊んでて見つけた。勿論明示的に宣言すればいくつの tuple でも show できます。
Hugs> show (1, 2, 3, 4, 5) "(1,2,3,4,5)" Hugs> show (1, 2, 3, 4, 5, 6) ERROR - Cannot infer instance *** Instance : Show (f,e,d,c,b,a) *** Expression : show (1,2,3,4,5,6)
GHC では何 tuple でも自動的に Show instance になります。
ちなみに Haskell 98 Report は:
instance (Show a, Show b) => Show (a,b) where showsPrec p (x,y) = showChar '(' . shows x . showChar ',' . shows y . showChar ')' instance (Read a, Read b) => Read (a,b) where readsPrec p = readParen False (\r -> [((x,y), w) | ("(",s) <- lex r, (x,t) <- reads s, (",",u) <- lex t, (y,v) <- reads u, (")",w) <- lex v ] ) -- Other tuples have similar Read and Show instances