有没有办法在ghci中查看特定类型的Typeclass定义?在ghci中查看特定类型的定义
例如,Maybe
定义是这样的:
instance Functor Maybe where
fmap f (Just x) = Just (f x)
fmap f Nothing = Nothing
我可以看到这个在ghci中?
的时候,我在ghci中使用:info
,我得到这个:
Prelude> :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'
在上面的输出,我想看看它是如何在Data.Maybe定义为实例Functor
。无论如何看到在ghci?
在您自己的机器上运行hoogle相当简单('cabal install; hoogle data')。 – aavogt
@aavogt:对,但命令行搜索不会给你很好的链接,像在线版本的黑线鳕。将它用作本地服务器并不那么简单。 – leftaroundabout
为了搜索'data Double'和它的实现,比如说'+'符合'Num',这个方法仍然没有提供一种查看源代码的方法。 hoogle中的'Maybe'示例提供了一个与源代码的链接,但是一般来说它并不是。 – ely