-> (Integer, Stack) push c cs = (c, c:cs) pop :: Stack -> (Integer, Stack) pop (c:cs) = (c, cs) main = do let stack = [1, 2, 3, 4, 5] let (i1, stack1) = pop stack let (i2, stack2) = pop stack1 let (i3, stack3) = push (i1 + i2) stack2 print (i3, stack3)
StackOp a b = StackOp { run :: Stack a -> (b, Stack a) } ܕͷҰൠԽ https://github.com/pnlybubbles-gomibako/counter-haskell/blob/master/stack7.hs class MyMonad m where bind :: m b -> (b -> m c) -> m c bind_ :: m b -> m c -> m c unit :: b -> m b Ϟφυ(ͷΑ͏ͳͷ)
Show type StackOp a b = State (Stack a) b https://github.com/pnlybubbles-gomibako/counter-haskell/blob/master/stack8.hs push :: a -> StackOp a a push c = get >>= \(Stack cs) -> put (Stack (c:cs)) >> return c