Haskell 应用程序的左星和右星测序操作符应该做什么?

Haskell 应用程序的左星和右星测序操作符应该做什么?,haskell,applicative,Haskell,Applicative,我查看了实现,它更神秘: -- | Sequence actions, discarding the value of the first argument. (*>) :: f a -> f b -> f b a1 *> a2 = (id <$ a1) <*> a2 -- This is essentially the same as liftA2 (flip const), but if the -- Functor instance has an

我查看了实现,它更神秘:

-- | Sequence actions, discarding the value of the first argument.
(*>) :: f a -> f b -> f b
a1 *> a2 = (id <$ a1) <*> a2
-- This is essentially the same as liftA2 (flip const), but if the
-- Functor instance has an optimized (<$), it may be better to use
-- that instead. Before liftA2 became a method, this definition
-- was strictly better, but now it depends on the functor. For a
-- functor supporting a sharing-enhancing (<$), this definition
-- may reduce allocation by preventing a1 from ever being fully
-- realized. In an implementation with a boring (<$) but an optimizing
-- liftA2, it would likely be better to define (*>) using liftA2.

-- | Sequence actions, discarding the value of the second argument.
(<*) :: f a -> f b -> f a
(<*) = liftA2 const
——|对操作进行排序,丢弃第一个参数的值。
(*>)::FA->FB->FB

a1*>a2=(id这些运算符对两个应用程序操作进行排序,并提供箭头指向的操作的结果。例如

> Just 1 *> Just 2
Just 2

> Just 1 <* Just 2
Just 1
>只有1个*>只有2个
只有两个
>仅1 p)
(>>)
相同,但只需要
应用程序
约束,而不是
Monad
约束


我甚至不明白为什么
liftA2(翻转常量)fa fb
=
fmap(\a b->b)fa fb
=
fmap(常量id)fa fb
=
常量id fa fb
(=
id和
fa a)fa fb
。将其与使用
(,)
=
\ab->(a,b)
时进行比较,如上所述。确实,递归类型需要在编写
fmap
时谨慎,以允许它内联到默认的
数据中。Sequence.Seq
是一个具有特别有效
的类型的好例子
brackets p = char '(' *> p <* char ')'