【发布时间】:2021-03-09 22:09:10
【问题描述】:
对于任何Applicative 实例,一旦写入<*>,pure 就会被唯一确定。假设您有pure1 和pure2,两者都遵守法律。那么
pure2 f <*> pure1 y = pure1 ($ y) <*> pure2 f -- interchange for pure1
pure2 id <*> pure1 y = pure1 ($ y) <*> pure2 id -- specialize f to id
pure1 y = pure1 ($ y) <*> pure2 id -- identity for pure2
pure1 y = fmap ($ y) (pure2 id) -- applicative/fmap law for pure1
pure1 y = pure2 ($ y) <*> pure2 id -- applicative/fmap law for pure2
pure1 y = pure2 y -- homomorphism law
但是以这种方式使用fmap 法律感觉就像在作弊。有没有办法在不诉诸参数化的情况下避免这种情况?
【问题讨论】:
-
有趣。我敢肯定,鉴于
<*>并不是真正的应用程序的“基本”方法,即monoidal functors——它是fzip :: f a -> f b -> f (a,b)。但是,我只是不太明白您所说的“感觉像是作弊”的意思。你只是在使用法律,这怎么可能是作弊呢。 -
@leftaroundabout,我想我真正的意思是
fmap的唯一性(这意味着fmap/Applicative法则)来自参数化。因此,如果您将这些定律排除在参数性成立的背景之外,那么就会产生一个问题:pure是否仍然由<*>决定,或者它实际上是否仅由fmap与<*>的组合决定。跨度> -
我还想知道
fzip和funit :: f ()会如何回答这类问题。
标签: haskell applicative