在Haskell中,整型类型类是否意味着显示类型类?

在Haskell中,整型类型类是否意味着显示类型类?,haskell,typeclass,Haskell,Typeclass,我试图编译这段代码 symmetric [] = True symmetric [_] = True symmetric l | (head l) == (last l) = symmetric (tail (init l)) | otherwise = False isPalindrome :: Integral a => a -> Bool isPalindrome n = symmetric (show n) 那段代码没有编译,我得到了一个不太长的警告 错误

我试图编译这段代码

symmetric [] = True
symmetric [_] = True
symmetric l
    | (head l) == (last l) = symmetric (tail (init l))
    | otherwise = False

isPalindrome :: Integral a => a -> Bool
isPalindrome n = symmetric (show n)
那段代码没有编译,我得到了一个不太长的警告 错误消息,表示无法推断(显示a)

换了这条线后它就工作了

isPalindrome :: Integral a => a -> Bool

所以我在想,既然整数中的每一种类型都在显示中,Haskell编译器应该能够从(整数a)推导(显示a)

所以我在想,既然积分的每一种类型都在展示中

但并非
Integral
中的所有类型都在
Show
中。Haskell 98的情况就是这样,因为

class Show n => Num n
但这种超类关系阻止了大量有用的数字类型(“无限精度数字”、连续函数的全局结果等)。在现代Haskell中,
Show
类和
Integral
类根本没有关系,因此编译器无法从中推断出一个类和另一个类

然而,确实可以独立于实际的
show
类显示任何整数类型;使用此函数进行此操作

import Numeric (showInt)
isPalindrome :: Integral a => a -> Bool
isPalindrome n = symmetric $ showInt n []

积分并不一定意味着显示会员资格。我可以创建自己的积分类型,而不是实现show。
class Show n => Num n
import Numeric (showInt)
isPalindrome :: Integral a => a -> Bool
isPalindrome n = symmetric $ showInt n []