    -----------------------------------------------------------------------------

    -- |
    -- Module      :  Distribution.Compat.SnocList
    -- License     :  BSD3
    --
    -- Maintainer  :  cabal-dev@haskell.org
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- A very reversed list. Has efficient `snoc`
    module Distribution.Compat.SnocList
      ( SnocList
      , runSnocList
      , snoc
      ) where

    import Distribution.Compat.Prelude
    import Prelude ()

    newtype SnocList a = SnocList [a]

    snoc :: SnocList a -> a -> SnocList a
    snoc :: forall a. SnocList a -> a -> SnocList a
    snoc (SnocList [a]
    xs) a
    x = [a] -> SnocList a
    forall a. [a] -> SnocList a
    SnocList (a
    x a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : [a]
    xs)

    runSnocList :: SnocList a -> [a]
    runSnocList :: forall a. SnocList a -> [a]
    runSnocList (SnocList [a]
    xs) = [a] -> [a]
    forall a. [a] -> [a]
    reverse [a]
    xs

    instance Semigroup (SnocList a) where
      SnocList [a]
    xs <> :: SnocList a -> SnocList a -> SnocList a
    <> SnocList [a]
    ys = [a] -> SnocList a
    forall a. [a] -> SnocList a
    SnocList ([a]
    ys [a] -> [a] -> [a]
    forall a. Semigroup a => a -> a -> a
    <> [a]
    xs)

    instance Monoid (SnocList a) where
      mempty :: SnocList a
    mempty = [a] -> SnocList a
    forall a. [a] -> SnocList a
    SnocList []
      mappend :: SnocList a -> SnocList a -> SnocList a
    mappend = SnocList a -> SnocList a -> SnocList a
    forall a. Semigroup a => a -> a -> a
    (<>)