monadic stack implementation
monadic stack implementation