我想出了这个:
Prelude> let a = \x -> print x
Prelude> let b = \x -> return x
Prelude> b 123 >>= a
123
我的问题是,脚本版本无法编译:
monad_1.hs:2:11:
No instance for (Monad m0) arising from a use of ‘return’
The type variable ‘m0’ is ambiguous
Relevant bindings include b :: a -> m0 a (bound at monad_1.hs:2:1)
Note: there are several potential instances:
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
...plus one other
In the expression: return x
In the expression: \ x -> return x
In an equation for ‘b’: b = \ x -> return x