相关疑难解决方法(0)

"return"关键字有什么特别之处

当我似乎理解Haskell的回归时,我尝试使用不同的替代方案,似乎返回不仅可以在monad链中的任何地方使用,而且可以完全排除

*Main> Just 9 >>= \y -> (Just y) >>= \x -> return x
Just 9

*Main> Just 9 >>= \y -> (return y) >>= \x -> (Just y)
Just 9

*Main> Just 9 >>= \y -> (Just y) >>= \x -> (Just x)
Just 9 
Run Code Online (Sandbox Code Playgroud)

即使我在自己的实例中省略了返回,我也只会收到警告......

data MaybeG a = NothingG | JustG a deriving Show 
instance Monad MaybeG where  
    --    return x = JustG x  
        NothingG >>= f = NothingG  
        JustG x >>= f  = f x  
        fail …
Run Code Online (Sandbox Code Playgroud)

monads haskell functional-programming

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

functional-programming ×1

haskell ×1

monads ×1