为什么ghci输出(Num a)=> a for:t 4而不是(Ord a)=> a?

Dat*_*yte 4 haskell types type-inference typeclass

当我进入:t 4ghci时,我得到了

Prelude> :t 4
4 :: Num t => t
Run Code Online (Sandbox Code Playgroud)

我理解为什么4不仅仅是一个Int或一个整数,而且它是自下而上的,但我不明白为什么4没有显示为这样Ord t => t或更正确的东西:

4 :: (Ord t || Num t) => t
Run Code Online (Sandbox Code Playgroud)

因为4既是OrdNum,但OrdNum没有连接...

那么为什么:t 4只输出Num

Ale*_*lec 9

并非所有具有实例的类型Num都具有实例Ord,并且您只需要具有Haskell所具有的重载数字文字的fromInteger部分Num.例如,Complexfrom Data.Complex有一个Num实例但没有Ord.在这种情况下,4不是一个Ord.

ghci> import Data.Complex
ghci> let x = 1 :: Complex Double
ghci> let y = 2 :: Complex Double
ghci> x < y
<interactive>
    * No instance for (Ord (complex Double)) arising from use of `<'
    * In the expression: x < y
      In the equation for `it': it = x < y
ghci>
Run Code Online (Sandbox Code Playgroud)

正如@Lee评论的那样,这是报告中概述的行为.