Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created October 14, 2009 02:27
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/209731 to your computer and use it in GitHub Desktop.
Save jutememo/209731 to your computer and use it in GitHub Desktop.
module Mainbak01_01 where
import Stack
{-
comb :: Num a =>
(Stack a -> (a, Stack a))
-> (Stack a -> (a, Stack a))
-> Stack a -> (a, Stack a)
comb m n = \stack0 ->
let (x1, stack1) = m stack0
(x2, stack2) = n stack1
in (x1+x2, stack2)
-}
comb :: (Stack a -> (a, Stack a))
-> (Stack a -> (a, Stack a))
-> (a -> a -> a)
-> Stack a -> (a, Stack a)
comb m n f = \stack0 ->
let (x1, stack1) = m stack0
(x2, stack2) = n stack1
in (f x1 x2, stack2)
main = do
{-
print $ pop `comb` pop $ s
print $ pop `comb` pop `comb` pop $ s
-}
print $ (pop `comb` pop) (+) $ s
print $ ((pop `comb` pop) (+) `comb` pop) (*) $ s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment