ghci で型がどの型クラスのインスタンスであるかを確認します。質問する

ghci で型がどの型クラスのインスタンスであるかを確認します。質問する

型がどの型クラスを実装しているかを確認することは可能ですか? 次のようになります:

>:typeclasses Int
[Num, etc...]

ベストアンサー1

コマンドを使用します:info

Prelude> :info Int
data Int = GHC.Types.I# GHC.Prim.Int#   -- Defined in GHC.Types
instance Bounded Int -- Defined in GHC.Enum
instance Enum Int -- Defined in GHC.Enum
instance Eq Int -- Defined in GHC.Base
instance Integral Int -- Defined in GHC.Real
instance Num Int -- Defined in GHC.Num
instance Ord Int -- Defined in GHC.Base
instance Read Int -- Defined in GHC.Read
instance Real Int -- Defined in GHC.Real
instance Show Int -- Defined in GHC.Show

当然、このリストは現在インポートされているモジュールによって異なります。

Prelude> :info (->)
data (->) a b   -- Defined in GHC.Prim
Prelude> :m +Control.Monad.Instances
Prelude Control.Monad.Instances> :info (->)
data (->) a b   -- Defined in GHC.Prim
instance Monad ((->) r) -- Defined in Control.Monad.Instances
instance Functor ((->) r) -- Defined in Control.Monad.Instances

おすすめ記事