    {-# LANGUAGE DeriveDataTypeable #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Language.C.Data.Name
    -- Copyright   :  (c) 2008 Benedikt Huber
    -- License     :  BSD-style
    -- Maintainer  :  benedikt.huber@gmail.com
    -- Stability   :  experimental
    -- Portability :  ghc
    --
    -- Unique Names with fast equality (newtype 'Int')
    module Language.C.Data.Name (
    Name(..),newNameSupply, namesStartingFrom
    ) where
    import Data.Data (Data)
    import Data.Ix
    import GHC.Generics (Generic)
    import Control.DeepSeq (NFData)

    -- | Name is a unique identifier
    newtype Name = Name { Name -> Int
    nameId :: Int }
      deriving (Int -> Name -> ShowS
    [Name] -> ShowS
    Name -> String
    (Int -> Name -> ShowS)
    -> (Name -> String) -> ([Name] -> ShowS) -> Show Name
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Name -> ShowS
    showsPrec :: Int -> Name -> ShowS
    $cshow :: Name -> String
    show :: Name -> String
    $cshowList :: [Name] -> ShowS
    showList :: [Name] -> ShowS
    Show, ReadPrec [Name]
    ReadPrec Name
    Int -> ReadS Name
    ReadS [Name]
    (Int -> ReadS Name)
    -> ReadS [Name] -> ReadPrec Name -> ReadPrec [Name] -> Read Name
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Name
    readsPrec :: Int -> ReadS Name
    $creadList :: ReadS [Name]
    readList :: ReadS [Name]
    $creadPrec :: ReadPrec Name
    readPrec :: ReadPrec Name
    $creadListPrec :: ReadPrec [Name]
    readListPrec :: ReadPrec [Name]
    Read, Name -> Name -> Bool
    (Name -> Name -> Bool) -> (Name -> Name -> Bool) -> Eq Name
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Name -> Name -> Bool
    == :: Name -> Name -> Bool
    $c/= :: Name -> Name -> Bool
    /= :: Name -> Name -> Bool
    Eq, Eq Name
    Eq Name =>
    (Name -> Name -> Ordering)
    -> (Name -> Name -> Bool)
    -> (Name -> Name -> Bool)
    -> (Name -> Name -> Bool)
    -> (Name -> Name -> Bool)
    -> (Name -> Name -> Name)
    -> (Name -> Name -> Name)
    -> Ord Name
    Name -> Name -> Bool
    Name -> Name -> Ordering
    Name -> Name -> Name
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Name -> Name -> Ordering
    compare :: Name -> Name -> Ordering
    $c< :: Name -> Name -> Bool
    < :: Name -> Name -> Bool
    $c<= :: Name -> Name -> Bool
    <= :: Name -> Name -> Bool
    $c> :: Name -> Name -> Bool
    > :: Name -> Name -> Bool
    $c>= :: Name -> Name -> Bool
    >= :: Name -> Name -> Bool
    $cmax :: Name -> Name -> Name
    max :: Name -> Name -> Name
    $cmin :: Name -> Name -> Name
    min :: Name -> Name -> Name
    Ord, Ord Name
    Ord Name =>
    ((Name, Name) -> [Name])
    -> ((Name, Name) -> Name -> Int)
    -> ((Name, Name) -> Name -> Int)
    -> ((Name, Name) -> Name -> Bool)
    -> ((Name, Name) -> Int)
    -> ((Name, Name) -> Int)
    -> Ix Name
    (Name, Name) -> Int
    (Name, Name) -> [Name]
    (Name, Name) -> Name -> Bool
    (Name, Name) -> Name -> Int
    forall a.
    Ord a =>
    ((a, a) -> [a])
    -> ((a, a) -> a -> Int)
    -> ((a, a) -> a -> Int)
    -> ((a, a) -> a -> Bool)
    -> ((a, a) -> Int)
    -> ((a, a) -> Int)
    -> Ix a
    $crange :: (Name, Name) -> [Name]
    range :: (Name, Name) -> [Name]
    $cindex :: (Name, Name) -> Name -> Int
    index :: (Name, Name) -> Name -> Int
    $cunsafeIndex :: (Name, Name) -> Name -> Int
    unsafeIndex :: (Name, Name) -> Name -> Int
    $cinRange :: (Name, Name) -> Name -> Bool
    inRange :: (Name, Name) -> Name -> Bool
    $crangeSize :: (Name, Name) -> Int
    rangeSize :: (Name, Name) -> Int
    $cunsafeRangeSize :: (Name, Name) -> Int
    unsafeRangeSize :: (Name, Name) -> Int
    Ix, Typeable Name
    Typeable Name =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> Name -> c Name)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c Name)
    -> (Name -> Constr)
    -> (Name -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c Name))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name))
    -> ((forall b. Data b => b -> b) -> Name -> Name)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Name -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Name -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Name -> m Name)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Name -> m Name)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Name -> m Name)
    -> Data Name
    Name -> Constr
    Name -> DataType
    (forall b. Data b => b -> b) -> Name -> Name
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
    forall u. (forall d. Data d => d -> u) -> Name -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Name
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Name -> c Name
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Name)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Name -> c Name
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Name -> c Name
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Name
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Name
    $ctoConstr :: Name -> Constr
    toConstr :: Name -> Constr
    $cdataTypeOf :: Name -> DataType
    dataTypeOf :: Name -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Name)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Name)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)
    $cgmapT :: (forall b. Data b => b -> b) -> Name -> Name
    gmapT :: (forall b. Data b => b -> b) -> Name -> Name
    $cgmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Name -> m Name
    Data, (forall x. Name -> Rep Name x)
    -> (forall x. Rep Name x -> Name) -> Generic Name
    forall x. Rep Name x -> Name
    forall x. Name -> Rep Name x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. Name -> Rep Name x
    from :: forall x. Name -> Rep Name x
    $cto :: forall x. Rep Name x -> Name
    to :: forall x. Rep Name x -> Name
    Generic)

    instance NFData Name

    instance Enum Name where
        toEnum :: Int -> Name
    toEnum = Int -> Name
    Name
        fromEnum :: Name -> Int
    fromEnum (Name Int
    n) = Int
    n

    -- | return an infinite stream of 'Name's starting with @nameId@ 0
    newNameSupply :: [Name]
    newNameSupply :: [Name]
    newNameSupply = Int -> [Name]
    namesStartingFrom Int
    0

    -- | get the infinite stream of unique names starting from the given integer
    namesStartingFrom :: Int -> [Name]
    namesStartingFrom :: Int -> [Name]
    namesStartingFrom Int
    k = [Int -> Name
    Name Int
    k..]