{-# LANGUAGE DeriveFoldable    #-}
{-# LANGUAGE DeriveFunctor     #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE OverloadedStrings #-}

module Kempe.Name ( Name (..)
                  , TyName
                  ) where

import           Control.DeepSeq (NFData (..))
import qualified Data.Text       as T
import           Kempe.Unique
import           Prettyprinter   (Pretty (pretty))

data Name a = Name { Name a -> Text
name   :: T.Text
                   , Name a -> Unique
unique :: !Unique
                   , Name a -> a
loc    :: a
                   } deriving (a -> Name b -> Name a
(a -> b) -> Name a -> Name b
(forall a b. (a -> b) -> Name a -> Name b)
-> (forall a b. a -> Name b -> Name a) -> Functor Name
forall a b. a -> Name b -> Name a
forall a b. (a -> b) -> Name a -> Name b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Name b -> Name a
$c<$ :: forall a b. a -> Name b -> Name a
fmap :: (a -> b) -> Name a -> Name b
$cfmap :: forall a b. (a -> b) -> Name a -> Name b
Functor, Name a -> Bool
(a -> m) -> Name a -> m
(a -> b -> b) -> b -> Name a -> b
(forall m. Monoid m => Name m -> m)
-> (forall m a. Monoid m => (a -> m) -> Name a -> m)
-> (forall m a. Monoid m => (a -> m) -> Name a -> m)
-> (forall a b. (a -> b -> b) -> b -> Name a -> b)
-> (forall a b. (a -> b -> b) -> b -> Name a -> b)
-> (forall b a. (b -> a -> b) -> b -> Name a -> b)
-> (forall b a. (b -> a -> b) -> b -> Name a -> b)
-> (forall a. (a -> a -> a) -> Name a -> a)
-> (forall a. (a -> a -> a) -> Name a -> a)
-> (forall a. Name a -> [a])
-> (forall a. Name a -> Bool)
-> (forall a. Name a -> Int)
-> (forall a. Eq a => a -> Name a -> Bool)
-> (forall a. Ord a => Name a -> a)
-> (forall a. Ord a => Name a -> a)
-> (forall a. Num a => Name a -> a)
-> (forall a. Num a => Name a -> a)
-> Foldable Name
forall a. Eq a => a -> Name a -> Bool
forall a. Num a => Name a -> a
forall a. Ord a => Name a -> a
forall m. Monoid m => Name m -> m
forall a. Name a -> Bool
forall a. Name a -> Int
forall a. Name a -> [a]
forall a. (a -> a -> a) -> Name a -> a
forall m a. Monoid m => (a -> m) -> Name a -> m
forall b a. (b -> a -> b) -> b -> Name a -> b
forall a b. (a -> b -> b) -> b -> Name a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Name a -> a
$cproduct :: forall a. Num a => Name a -> a
sum :: Name a -> a
$csum :: forall a. Num a => Name a -> a
minimum :: Name a -> a
$cminimum :: forall a. Ord a => Name a -> a
maximum :: Name a -> a
$cmaximum :: forall a. Ord a => Name a -> a
elem :: a -> Name a -> Bool
$celem :: forall a. Eq a => a -> Name a -> Bool
length :: Name a -> Int
$clength :: forall a. Name a -> Int
null :: Name a -> Bool
$cnull :: forall a. Name a -> Bool
toList :: Name a -> [a]
$ctoList :: forall a. Name a -> [a]
foldl1 :: (a -> a -> a) -> Name a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Name a -> a
foldr1 :: (a -> a -> a) -> Name a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Name a -> a
foldl' :: (b -> a -> b) -> b -> Name a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Name a -> b
foldl :: (b -> a -> b) -> b -> Name a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Name a -> b
foldr' :: (a -> b -> b) -> b -> Name a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Name a -> b
foldr :: (a -> b -> b) -> b -> Name a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Name a -> b
foldMap' :: (a -> m) -> Name a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Name a -> m
foldMap :: (a -> m) -> Name a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Name a -> m
fold :: Name m -> m
$cfold :: forall m. Monoid m => Name m -> m
Foldable, Functor Name
Foldable Name
Functor Name
-> Foldable Name
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Name a -> f (Name b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Name (f a) -> f (Name a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Name a -> m (Name b))
-> (forall (m :: * -> *) a. Monad m => Name (m a) -> m (Name a))
-> Traversable Name
(a -> f b) -> Name a -> f (Name b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Name (m a) -> m (Name a)
forall (f :: * -> *) a. Applicative f => Name (f a) -> f (Name a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Name a -> m (Name b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Name a -> f (Name b)
sequence :: Name (m a) -> m (Name a)
$csequence :: forall (m :: * -> *) a. Monad m => Name (m a) -> m (Name a)
mapM :: (a -> m b) -> Name a -> m (Name b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Name a -> m (Name b)
sequenceA :: Name (f a) -> f (Name a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Name (f a) -> f (Name a)
traverse :: (a -> f b) -> Name a -> f (Name b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Name a -> f (Name b)
$cp2Traversable :: Foldable Name
$cp1Traversable :: Functor Name
Traversable)

instance Eq (Name a) where
    == :: Name a -> Name a -> Bool
(==) (Name Text
_ Unique
u a
_) (Name Text
_ Unique
u' a
_) = Unique
u Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== Unique
u'

instance Pretty (Name a) where
    pretty :: Name a -> Doc ann
pretty (Name Text
t Unique
u a
_) = Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
t Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"_" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Unique -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Unique
u

instance Ord (Name a) where
    compare :: Name a -> Name a -> Ordering
compare (Name Text
_ Unique
u a
_) (Name Text
_ Unique
u' a
_) = Unique -> Unique -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Unique
u Unique
u'

instance NFData a => NFData (Name a) where
    rnf :: Name a -> ()
rnf (Name Text
_ Unique
u a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x () -> () -> ()
`seq` Unique
u Unique -> () -> ()
`seq` ()

type TyName = Name