Rag*_*iis 2 monads haskell bind operators operator-precedence
我试图理解如何单子的绑定运营商的作品,却发现这是一个奇怪的例子,因为明显的关联性没有意义,我考虑到这样的事实>>=被留下-associative。这是在解释器提示下进行测试的示例:
> Just 3 >>= \x -> Just "!" >>= \y -> Just (show x ++ y)
Just "3!"
> Just 3 >>= (\x -> Just "!" >>= (\y -> Just (show x ++ y)))
Just "3!"
> (Just 3 >>= \x -> Just "!" )>>= \y -> Just (show x ++ y)
<interactive>:3:50: error: Variable not in scope: x :: ()
Run Code Online (Sandbox Code Playgroud)
我不明白,因为第二个例子与第三个例子相反,因为它似乎与已知的结合性相矛盾。我知道我错过了一些东西,但我不知道是什么。