两个函数如何同时使用一个参数

Bul*_* M. 2 haskell

我正在阅读有关应用仿函数的文章,并找到了这样一句话:

(+) <$> (+3) <*> (*100) $ 5
Run Code Online (Sandbox Code Playgroud)

它输出508.

(+3)和(*100)如何同时使用5?为什么我们不需要传递两个5作为参数,如:

(+) <$> (+3) <*> (*100) $ 5 5
Run Code Online (Sandbox Code Playgroud)

chi*_*chi 7

(->) a应用实例中,我们发现:

instance Applicative ((->) a) where
    pure = const
    (<*>) f g x = f x (g x)
    liftA2 q f g x = q (f x) (g x)
Run Code Online (Sandbox Code Playgroud)

因此,x传递给两者f并按g定义传递.

  • @Bulat M. `(+) <$> (+3)` is `f`, `(*100)` is `g` and `5` is `x` (3认同)