【发布时间】:2015-11-23 17:58:14
【问题描述】:
instance Monoid m => Applicative (Const m) where
pure _ = Const mempty
Const f <*> Const v = Const (f `mappend` v)
我不明白<*>的定义怎么能类型检查。
左侧f受<*>的签名约束,如Applicative的定义中一样
class Functor f => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
改名后的现状:
(<*>) :: c (m -> b) -> c m -> c b
=> f :: m -> *.
左侧f是mappend的[第一个]参数。
从 Monoid 的定义
class Monoid a where
mempty :: a
-- ^ Identity of 'mappend'
mappend :: a -> a -> a
改名后的现状:
mappend :: m -> m -> m
=> f :: m.
【问题讨论】:
标签: haskell applicative monoids