我可以看到数据构造函数和实例,比如ghci中的Maybe
:
Prelude Control.Applicative> :i Maybe
data Maybe a = Nothing | Just a -- Defined in `Data.Maybe'
instance Eq a => Eq (Maybe a) -- Defined in `Data.Maybe'
instance Monad Maybe -- Defined in `Data.Maybe'
instance Functor Maybe -- Defined in `Data.Maybe'
instance Ord a => Ord (Maybe a) -- Defined in `Data.Maybe'
instance Read a => Read (Maybe a) -- Defined in `GHC.Read'
instance Show a => Show (Maybe a) -- Defined in `GHC.Show'
instance Applicative Maybe -- Defined in `Control.Applicative'
instance Alternative Maybe -- Defined in `Control.Applicative'
我也可以看到ghci中如何定义Applicative
类型类:
Prelude Control.Applicative> :i Applicative
class Functor f => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(*>) :: f a -> f b -> f b
(<*) :: f a -> f b -> f a
-- Defined in `Control.Applicative'
instance Applicative [] -- Defined in `Control.Applicative'
instance Applicative ZipList -- Defined in `Control.Applicative'
instance Monad m => Applicative (WrappedMonad m)
-- Defined in `Control.Applicative'
instance Applicative Maybe -- Defined in `Control.Applicative'
instance Applicative IO -- Defined in `Control.Applicative'
instance Applicative (Either e) -- Defined in `Control.Applicative'
instance Applicative ((->) a) -- Defined in `Control.Applicative'
但如何查找某个类型的特定实例的信息,例如instance Alternative Maybe
?
答案 0 :(得分:4)
ghci
没有任何命令可以显示函数和实例的基础源,但如果确实如此,它会很简洁。
我找到这些东西的来源的方法是找到它们的hackage(对于base
中的东西,hoogle是要走的路)。然后是黑线鳕include links to source from the documentation。