我可以在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
)的信息呢?
instance Alternative Maybe
)。然而,GHCi 只能处理多种编译后的代码表示方式,所以遗憾的是,你无法通过向它请求打印实例的源代码来得到太多帮助。 - daniel gratzer