I am currently trying to understand the do notation as taught in: http://learnyouahaskell.com/for-a-few-monads-more ...Here it is applied to simple functions and not a monad.
type Stack = [Int]
push :: Int -> Stack -> ((), Stack)
push a stack = ((),a:stack)
pop :: Stack -> (Int, Stack)
pop (x:xs) = (x, xs)
I dont understand the do-syntax fully, I am curious: Is this
turnipStack2 :: Stack -> (Int, Stack)
turnipStack = do
push 3
c <- pop
pop
.. the same as
turnipStack :: Stack -> (Int, Stack)
turnipStack = do
push 3
c <- pop
return c
If so, why is that. And could I have done the first mentioned without writing pop
in the end. In that case I get an error although I don't understand it.