Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created October 14, 2009 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/209759 to your computer and use it in GitHub Desktop.
Save jutememo/209759 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment