Tomer
Tomer

Reputation: 1229

Cascading the bind (`>>=`) operator

I have the following function

bar :: (Monad m, Num b) => m b -> m b -> m b -> m b 
bar x y z = do
              x' <- x
              y' <- y
              z' <- z
              return $ x' + y' + z'

and I'm trying to write it without the 'do' block. I tried

bar' :: (Monad m, Num b) => m b -> m b -> m b -> m b
bar' x y z = x >>=  ( \x' -> y >>= (\y' -> z >>= (\z' -> (x' + y' + z') ) ))

But I can't get it to work - I get

  error:
    * Occurs check: cannot construct the infinite type: b ~ m b
    * In the expression: x' + y' + z'

Any idea ?

Thanks!

Upvotes: 1

Views: 90

Answers (0)

Related Questions