Consider the following valid Haskell code
module Main where main :: IO () main = do let x = f print x f :: Maybe (Int, Int) f = Just 3 >>= (\a -> Just 5 >>= (\b -> return (a, b)))
where the function f can be rewritten equivalent to the so-called do-notation
f :: Maybe (Int, Int) f = do a <- Just 3 b <- Just 5 return (a, b)
Which annoys me, the notation will not work when I put the contents of f inline. The following code does not even parse:
main :: IO () main = do let x = do a <- Just 3 b <- Just 5 return (a, b) print x
I correct that inside let I have to resort to (>>=) ?
While I am, the following code does not parse:
module Main where main :: IO () main = do let x = Just 3 >>= (\a -> Just 5 >>= (\b -> return (a, b))) print x
I see no obvious reason other than the unnecessary limited power of let . Is there an elegant way to use bind inside let ?
source share