ghci中:info
的输出是否有理由列出它所属的每个类后的类型名称?例如
Prelude> :info Int`
打印
...
instance Bounded Int -- Defined in `GHC.Enum'
instance Enum Int -- Defined in `GHC.Enum'
instance Eq Int -- Defined in `GHC.Classes*emphasized text*'
...
我更喜欢读的是:
Prelude> :info Int
...
instance Bounded -- Defined in `GHC.Enum'
instance Enum -- Defined in `GHC.Enum'
instance Eq -- Defined in `GHC.Classes*emphasized text*'
...
或更好的是简短的符号,如
Prelude> :info Int
...
instance of Bounded, Enum, Eq,...
答案 0 :(得分:7)
也许,一个原因是参数化类型。为了说明我的观点,请看这个例子:
$ ghci -XMultiParamTypeClasses -XFlexibleInstances
-- ...
Prelude> class Klass a b c where {f :: a b c -> c}
Prelude> data Typ b c = Typ b c
Prelude> instance Klass Typ b Integer where { f (Typ _ c) = c + 1 }
Prelude> let x = Typ "a" 3
Prelude> f x
4
Prelude> :info Typ
data Typ b c = Typ b c -- Defined at <interactive>:3:6
instance Klass Typ b Integer -- Defined at <interactive>:4:10