当我在ghci中输入:t 4
我得到为什么ghci输出(Num a)=> a for:t 4而不是(Ord a)=> a?
Prelude> :t 4
4 :: Num t => t
我明白为什么4
不仅是int或一个整数,它是infered底了,但我不明白为什么4
不作为的Ord t => t
或更正确的是这样的:
4 :: (Ord t || Num t) => t
因为4
既是Ord
和Num
但Ord
和Num
有没有关系。
那么为什么:t 4
只输出Num
?
这在[haskell报告]中描述(https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1360006.4.1) – Lee
假设我给了'4'类型'Ord t = > t'。现在我注意到'Bool'是'Ord'的一个实例。因此'4 :: Bool'。 “4 :: Bool”应该是“真”还是“假”,为什么? –
@李Btw,有类似的问题关于类型违约规则:https://stackoverflow.com/questions/39251728/ghci-randomio-type-inference我试图回答它,理解报告,但仍然没有明确的看法。也许更有经验的_Haskell_用户可以帮助:) – Shersh