将ghci片段转换为脚本

时间:2017-01-01 21:24:20

标签: haskell

我想出了这个:

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

0 个答案:

没有答案