0

:infoghci 的输出在它所属的每个类之后列出类型名称是否有原因?例如

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,...
4

1 回答 1

8

也许,一个原因是参数化类型。为了说明我的观点,看这个例子:

$ 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
于 2013-03-24T13:45:41.867 回答