Add airlocks
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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,[])
|
||||
|
||||
singleton :: a -> DS a
|
||||
singleton x = DS (x,[],[])
|
||||
|
||||
head (DS (x,_,_)) = x
|
||||
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
|
||||
Reference in New Issue
Block a user