我是Haskell语言的新手。 我刚刚开始使用Monads,O根本无法弄清楚它是如何工作的。 我试着从 也许像这样称呼<=<
monad :(x->Just (x+1)) <=< (y -> Just (y *2)) $8
期待结果Just 17
. 但它显示了错误:
<interactive>:45:19: error:
* Variable not in scope:
(<=>)
:: (Integer -> Maybe Integer)
-> (Integer -> Maybe Integer) -> Integer -> t
* Perhaps you meant one of these:
`<>' (imported from Prelude), `<*>' (imported from Prelude),
`<=' (imported from Prelude)
这是代码:
(<=<) :: (a -> Maybe b) -> (c -> Maybe a) -> c -> Maybe b
f <=< g = ( x -> g x >>= f)
该运算符在Prelude
中不可用,您需要从Control.Monad
导入。例如,将其添加到文件顶部:
import Control.Monad ((<=<))