我具有此数据类型data SigT a p = ExistT a p
,并且我想为其编写指定的Show
。我尝试过:
instance Show (SigT Integer Integer) where
show (ExistT q r) = "quotient = " ++ show q ++ "remainder = " ++ show r
但是我得到这个错误:
EXAMPLE_05_Driver.hs:8:10: error:
• Illegal instance declaration for ‘Show (SigT Integer Integer)’
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use FlexibleInstances if you want to disable this.)
• In the instance declaration for ‘Show (SigT Integer Integer)’
答案 0 :(得分:5)
您是否已阅读错误消息的这一部分:“如果要禁用此功能,请使用FlexibleInstances”。这是指FlexibleInstances
语言扩展,您可以通过编写使其启用
{-# LANGUAGE FlexibleInstances #-}
位于源文件的顶部,或者(如果您使用的是ghci)则通过编写:set -XFlexibleInstances