module Mainbak01 where import Stack comb :: (Stack a -> (a, Stack a)) -> (a -> (Stack a -> (a, Stack a))) -> Stack a -> (a, Stack a) comb m n = \stack0 -> let (x1, stack1) = m stack0 (x2, stack2) = n x1 stack1 in (x2, stack2) ret :: a -> (Stack a -> (a, Stack a)) ret x = \stack -> (x, stack) comb_ :: (Stack a -> (a, Stack a)) -> (Stack a -> (a, Stack a)) -> Stack a -> (a, Stack a) comb_ m n = m `comb` (\_ -> n) main = do print $ pop `comb` (\x1 -> pop) $ s print $ pop `comb` (\x1 -> pop `comb` \x2 -> ret(x1 + x2)) $ s print $ pop `comb` (\x1 -> pop `comb` \x2 -> pop `comb` \x3 -> ret $ (x1 + x3) * x2) $ s