-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | reversed lists/snoc lists
--
-- The key idea of this library is to leverage the type system to control
-- the performance characteristics of list-manipulation code. It defines
-- the type RList, which is a snoc-list rather than a cons-list.
-- It also creates a symmetric module for cons-lists, which focuses on
-- the efficient and safe use of linked lists. See README.md for more
-- information.
@package reverse-list
@version 0.3.0.0
-- | This module exists primarily for symmetry with Data.List.Snoc
-- However, it can also be used in place of the Prelude list type:
--
-- This module only exports functions that are efficient on linked lists.
-- Many functions on that type (last, isSuffixOf) though
-- technically implementable, do not represent the intended use of a
-- linked list in terms of performance.
--
-- Additionally, this module does not export any partial functions:
-- head and tail return their results under a Maybe.
module Data.List.Cons
-- | As a counterpart to Tsil.
type List = ([])
-- | An empty List, such as nil.
pattern Nil :: List a
-- | The List consisting of head and tail elements, such as created
-- by cons.
pattern Cons :: a -> List a -> List a
-- | The empty List.
nil :: List a
-- | O(1) Append an element.
--
-- If you are looking for snoc, you should use an Tsil,
-- or a finite sequence/queue type.
cons :: a -> List a -> List a
-- | O(1) Access the first element and trailing portion of the
-- list. See also head and tail if you only need one
-- component.
--
-- If you are looking for unsnoc, you should use an Tsil,
-- or a finite sequence/queue type.
uncons :: List a -> Maybe (a, List a)
-- | Create a single-element List.
singleton :: a -> List a
-- | O(1) extract the first element of a list, if it exists. See
-- also uncons if you also need tail at the same time.
head :: List a -> Maybe a
-- | O(1) extract the elements of a list other than the last, if
-- they exist. See also uncons if you also need head at the
-- same time.
tail :: List a -> Maybe (List a)
-- | Useful for describing zippers and functional queues/buffers more
-- naturally and safely.
--
-- We call it an RList because this is really just a vanilla list,
-- but where the semantics are that the last-added thing (internally
-- cons'ed) is understood to be at the "end" of the list.
module Data.List.Snoc
-- | This datatype defines snoc-lists: lists with O(1) append and O(n)
-- prepend. Underneath the hood, it is just a plain list, but understood
-- as containing its elements in reverse order.
--
-- | See? It's "List" in reverse? I dunno, I just think RList is
-- an inelegant name, and word-initial t͜s is one of my
-- favorite phonemes.
data Tsil a
-- | I initially went with this boring name for reverse-lists. However, I
-- genuinely would rather write (and pronounce) Tsil.
-- | Deprecated: Preferred spelling is Tsil
type RList = Tsil
-- | The empty Tsil.
nil :: Tsil a
-- | O(1) Append an element.
--
-- If you are looking for cons, you should use a plain list, or
-- a finite sequence/queue type.
snoc :: Tsil a -> a -> Tsil a
-- | Create a single-element Tsil.
singleton :: a -> Tsil a
-- | O(1) Access the last element and initial portion of the list.
-- See also last and init if you only need one component.
--
-- If you are looking for uncons, you should use a plain list,
-- or a finite sequence/queue type.
unsnoc :: Tsil a -> Maybe (Tsil a, a)
-- | An empty RList, such as nil.
pattern Nil :: Tsil a
-- | The Tsil consisting of initial and last elements, such as
-- created by snoc.
pattern Snoc :: Tsil a -> a -> Tsil a
-- | Test if an Tsil is empty.
null :: Tsil a -> Bool
-- | O(1) extract the elements of a list other than the last, if
-- they exist. See also unsnoc if you also need last at the
-- same time.
init :: Tsil a -> Maybe (Tsil a)
-- | O(1) extract the last element of a list, if it exists. See
-- also unsnoc if you also need init at the same time.
last :: Tsil a -> Maybe a
-- | Remove all Nothings from an Tsil of Maybes.
catMaybes :: Tsil (Maybe a) -> Tsil a
-- | O(n) Convert to a plain list, maintaining order.
--
-- This is here so that you can escape back out to normal cons-list land
-- once you're done building your list.
--
-- See reverseOut for when order doesn't matter.
toList :: Tsil a -> [a]
-- | O(n) Convert from a plain list, maintaining order.
--
-- This is added for completion's sake, as I'm not sure you'll often need
-- this adapter.
--
-- See toList for the inverse, or reverseIn for when order
-- doesn't matter.
fromList :: [a] -> Tsil a
-- | O(0) Reverse a plain cons list, rerutning an Tsil.
--
-- See reverseOut for the inverse, and why you might use these.
reverseIn :: [a] -> Tsil a
-- | O(0) Reverse an Tsil, returning a plain cons list.
--
-- This is here so that when the output list is fed to an order-agnostic
-- function, you don't have to pay the cost of reversing the
-- representation.
--
-- See toList for when order matters.
reverseOut :: Tsil a -> [a]
-- | Write the contents of the Tsil into an array, assuming you know
-- the length of the array. This is useful in the common case of
-- buffering an unknown-length stream before allocating contiguous space
-- for the elements.
--
-- If you sepcify to small a langth, the initial part of the array will
-- be uninitialized. If you specify to large a length, the initial part
-- of the list will not be written.
--
-- If you are unaware of the size of the list, `Arr.fromList . fromList`
-- will do the trick, but will obviously be slower.
toArrayN :: (Contiguous arr, Element arr a) => Int -> Tsil a -> arr a
-- | Convert to a set without an intermediate conversion to a cons-list.
toSet :: Ord a => Tsil a -> Set a
instance GHC.Base.Applicative Data.List.Snoc.Tsil
instance GHC.Base.Functor Data.List.Snoc.Tsil
instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.List.Snoc.Tsil a)
instance GHC.Generics.Generic (Data.List.Snoc.Tsil a)
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Data.List.Snoc.Tsil a)
instance GHC.Show.Show a => GHC.Show.Show (Data.List.Snoc.Tsil a)
instance GHC.Read.Read a => GHC.Read.Read (Data.List.Snoc.Tsil a)
instance Data.Foldable.Foldable Data.List.Snoc.Tsil
instance GHC.Base.Semigroup (Data.List.Snoc.Tsil a)
instance GHC.Base.Monoid (Data.List.Snoc.Tsil a)
instance GHC.Base.Alternative Data.List.Snoc.Tsil