<<<<<<< HEAD import Control.Monad.State type Stack = [Int] --Define the pop function pop :: Stack -> (Int, Stack) pop (x:xs) = (x, xs) --Define the push function push :: Int -> Stack -> ((), Stack) push x xs = ((), x:xs) stackManip :: Stack -> (Int, Stack) stackManip stack = let (a, stack1) = pop stack (b, stack2) = pop stack1 ((), stack3) = push 100 stack2 (c, stack4) = pop stack3 in pop stack4 popM :: State Stack Int popM = do x:xs <- get put xs return x pushM :: Int -> State Stack () pushM a = do xs <- get put (a:xs) return() stackManipM :: State Stack Int stackManipM = do popM popM pushM 100 popM popM stackStuff :: State Stack () stackStuff = do a <- popM if (a==5) then return () else do pushM 3 pushM 8 get ======= --Define the Bilist type data Bilist a = Bilist [a] [a] deriving (Show, Eq) bilist_ref (Bilist l r) pos = (l !! pos, r !! pos) --Define oddeven oddeven :: [a] -> Bilist a oddeven l = oddevenh l [] [] oddevenh :: [a] -> [a] -> [a] -> Bilist a oddevenh [] ev od = Bilist ev od oddevenh (x:xs) ev od = oddevenh xs od (ev++[x]) --Define the inverse of oddeven inv_oddeven :: Bilist a -> [a] inv_oddeven (Bilist [] []) = [] inv_oddeven (Bilist (l:ls) (r:rs)) = [l] ++ [r] ++ (inv_oddeven (Bilist ls rs)) inv_oddeven2 :: Bilist a -> [a] inv_oddeven2 (Bilist l r) = foldl (++) [] $ map (\(x,y) -> [x,y]) $ zip l r bilist_max (Bilist (l:ls) (r:rs)) = bilist_maxh (Bilist ls rs) 2 (l+r) 1 bilist_maxh (Bilist (l:ls) (r:rs)) pos curmax maxpos | l+r > curmax = bilist_maxh (Bilist ls rs) (pos+1) (l+r) pos bilist_maxh (Bilist (l:ls) (r:rs)) pos curmax maxpos = bilist_maxh (Bilist ls rs) (pos+1) curmax maxpos bilist_maxh (Bilist [] []) pos curmax maxpos = maxpos >>>>>>> 66d23fcd2717ce0805f5442c6cf4888114f9b38c