剛剛被介紹給哈斯克爾的單子,並與>>
碰到了一些障礙。正確使用>>在Haskell
>>=
對我來說很有意義,因爲我可以得到下面的出前奏曲:
Prelude> Just 1 >>= (\ x -> Just (x+1))
Just 2
我的理解是,>>
是一樣的綁定,但僅用於當函數是關於恆定的參數。但是,當我嘗試這樣做,在前奏:
Prelude> Just 1 >> (\_ -> Just 10)
<interactive>:7:12: error:
• Couldn't match expected type ‘Maybe b’
with actual type ‘t0 -> Maybe Integer’
• The lambda expression ‘\ _ -> Just 10’ has one argument,
but its type ‘Maybe b’ has none
In the second argument of ‘(>>)’, namely ‘(\ _ -> Just 10)’
In the expression: Just 1 >> (\ _ -> Just 10)
• Relevant bindings include
it :: Maybe b (bound at <interactive>:7:1)
我非常努力破譯此錯誤消息...誰能與>>
正確使用幫助?我對此不瞭解的是什麼?
好,因爲''>>因素已經指出,'\ _ - >'你不必給它明確寫入。 –