module DoubleStack where newtype DS a = DS (a,[a],[a]) deriving (Eq, Ord, Read, Show) {- | Unsafe. -} fromListL :: [a] -> DS a fromListL (x:xs) = DS (x,xs,[]) fromListL _ = undefined singleton :: a -> DS a singleton x = DS (x,[],[]) head :: DS a -> a head (DS (x,_,_)) = x left, right :: DS a -> [a] left (DS (_,l,_)) = l right (DS (_,_,r)) = r pushL :: DS a -> DS a pushL (DS (x,xs, y:ys )) = DS (y, x:xs ,ys) pushL ds = ds pushR :: DS a -> DS a pushR (DS (y, x:xs ,ys)) = DS (x,xs, y:ys ) pushR ds = ds cycleL :: DS a -> Maybe (DS a) cycleL (DS (x,xs, y:ys )) = Just $ DS (y, x:xs ,ys) cycleL _ = Nothing cycleR :: DS a -> Maybe (DS a) cycleR (DS (y, x:xs ,ys)) = Just $ DS (x,xs, y:ys ) cycleR _ = Nothing