我注意到我不知道如何让GHCi打印关于复合类型的信息。让我们考虑一个例子:
data X a = X (a Int)
type XList = X []
instance Show XList where show (X l) = "X (" ++ show l ++ ")"
我希望看到"X []"实现Show。
尝试1
λ :i (X [])
<interactive>:1:2: error: parse error on input ‘X’
尝试2-打印列表的实例但不包括 (X [])
λ :i X []
第三次尝试 - 与实例无关
λ :i XList
type XList = X [] -- Defined at <interactive>:20:1
然而,当适用时,展示实例是有效的。
λ show (X [1,2,3])
"X ([1,2,3])"
λ show (X ['1'])
<interactive>:31:18: error:
• Couldn't match expected type ‘Int’ with actual type ‘Char’