我正在阅读Typeclassopedia,但在应用程序部分遇到了麻烦。我想我(有点)已经弄清楚了,但我想看看我的理解是否正确。
直到组合法出现之前,适用法则才有意义。我只是无法解析其右侧:
u <*> (v <*> w) = pure (.) <*> u <*> v <*> w
Run Code Online (Sandbox Code Playgroud)
因此,我启动了 GHCI 并进行了一些实验。
Prelude> pure (.) <*> Just (+1) <*> Just (+2) <*> Just 34
Just 37
Run Code Online (Sandbox Code Playgroud)
所以这验证了规律,但我还是不明白。我尝试了一些变化,看看是否可以获得一些见解:
Prelude> pure (.) <*> Just (+1) <*> Just (+2) <*> Just (+3) <*> Just 34
<interactive>:26:1: error:
* Non type-variable argument in the constraint: Num (b -> b)
(Use FlexibleContexts to permit this)
* When checking the inferred type
it :: forall b. (Num …Run Code Online (Sandbox Code Playgroud)