Skip to content

Commit

Permalink
rename Front to Full
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Feb 28, 2024
1 parent 9846e8e commit 97524c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/Queue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- * Okasaki, Chris. /Purely Functional Data Structures/. Diss. Princeton University, 1996.
module Queue
( -- * Queue
Queue (Empty, Front),
Queue (Empty, Full),

-- ** Initialization
empty,
Expand Down Expand Up @@ -67,7 +67,7 @@ instance Foldable Queue where
where
go = \case
Empty -> mempty
Front x xs -> f x <> go xs
Full x xs -> f x <> go xs

null :: Queue a -> Bool
null =
Expand All @@ -86,7 +86,7 @@ instance Monoid (Queue a) where
instance Semigroup (Queue a) where
(<>) :: Queue a -> Queue a -> Queue a
xs <> Empty = xs
xs <> Front y ys = enqueue y xs <> ys
xs <> Full y ys = enqueue y xs <> ys

instance (Show a) => Show (Queue a) where
show :: Queue a -> String
Expand All @@ -106,10 +106,10 @@ pattern Empty :: Queue a
pattern Empty <- (dequeue -> Nothing)

-- | The front of a queue, and the rest of it.
pattern Front :: a -> Queue a -> Queue a
pattern Front x xs <- (dequeue -> Just (x, xs))
pattern Full :: a -> Queue a -> Queue a
pattern Full x xs <- (dequeue -> Just (x, xs))

{-# COMPLETE Empty, Front #-}
{-# COMPLETE Empty, Full #-}

------------------------------------------------------------------------------------------------------------------------
-- Internal smart constructor utils
Expand Down
12 changes: 7 additions & 5 deletions src/Queue/Ephemeral.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- * Okasaki, Chris. /Purely Functional Data Structures/. Diss. Princeton University, 1996.
module Queue.Ephemeral
( -- * Ephemeral queue
EphemeralQueue (Empty, Front),
EphemeralQueue (Empty, Full),

-- ** Initialization
empty,
Expand Down Expand Up @@ -55,7 +55,7 @@ instance Foldable EphemeralQueue where
where
go = \case
Empty -> mempty
Front x xs -> f x <> go xs
Full x xs -> f x <> go xs

elem :: (Eq a) => a -> EphemeralQueue a -> Bool
elem x (Q xs ys) =
Expand Down Expand Up @@ -93,13 +93,15 @@ instance Traversable EphemeralQueue where
------------------------------------------------------------------------------------------------------------------------
-- Patterns

-- | An empty queue.
pattern Empty :: EphemeralQueue a
pattern Empty <- (dequeue -> Nothing)

pattern Front :: a -> EphemeralQueue a -> EphemeralQueue a
pattern Front x xs <- (dequeue -> Just (x, xs))
-- | The front of a queue, and the rest of it.
pattern Full :: a -> EphemeralQueue a -> EphemeralQueue a
pattern Full x xs <- (dequeue -> Just (x, xs))

{-# COMPLETE Empty, Front #-}
{-# COMPLETE Empty, Full #-}

------------------------------------------------------------------------------------------------------------------------
-- Initialization
Expand Down

0 comments on commit 97524c5

Please sign in to comment.