{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE StandaloneDeriving #-}
module FieldLabel ( FieldLabelString
, FieldLabelEnv
, FieldLbl(..)
, FieldLabel
, mkFieldLabelOccs
) where
import GhcPrelude
import OccName
import Name
import FastString
import FastStringEnv
import Outputable
import Binary
import Data.Data
type FieldLabelString = FastString
type FieldLabelEnv = DFastStringEnv FieldLabel
type FieldLabel = FieldLbl Name
data FieldLbl a = FieldLabel {
FieldLbl a -> FieldLabelString
flLabel :: FieldLabelString,
FieldLbl a -> Bool
flIsOverloaded :: Bool,
FieldLbl a -> a
flSelector :: a
}
deriving (FieldLbl a -> FieldLbl a -> Bool
(FieldLbl a -> FieldLbl a -> Bool)
-> (FieldLbl a -> FieldLbl a -> Bool) -> Eq (FieldLbl a)
forall a. Eq a => FieldLbl a -> FieldLbl a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldLbl a -> FieldLbl a -> Bool
$c/= :: forall a. Eq a => FieldLbl a -> FieldLbl a -> Bool
== :: FieldLbl a -> FieldLbl a -> Bool
$c== :: forall a. Eq a => FieldLbl a -> FieldLbl a -> Bool
Eq, a -> FieldLbl b -> FieldLbl a
(a -> b) -> FieldLbl a -> FieldLbl b
(forall a b. (a -> b) -> FieldLbl a -> FieldLbl b)
-> (forall a b. a -> FieldLbl b -> FieldLbl a) -> Functor FieldLbl
forall a b. a -> FieldLbl b -> FieldLbl a
forall a b. (a -> b) -> FieldLbl a -> FieldLbl b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> FieldLbl b -> FieldLbl a
$c<$ :: forall a b. a -> FieldLbl b -> FieldLbl a
fmap :: (a -> b) -> FieldLbl a -> FieldLbl b
$cfmap :: forall a b. (a -> b) -> FieldLbl a -> FieldLbl b
Functor, FieldLbl a -> Bool
(a -> m) -> FieldLbl a -> m
(a -> b -> b) -> b -> FieldLbl a -> b
(forall m. Monoid m => FieldLbl m -> m)
-> (forall m a. Monoid m => (a -> m) -> FieldLbl a -> m)
-> (forall m a. Monoid m => (a -> m) -> FieldLbl a -> m)
-> (forall a b. (a -> b -> b) -> b -> FieldLbl a -> b)
-> (forall a b. (a -> b -> b) -> b -> FieldLbl a -> b)
-> (forall b a. (b -> a -> b) -> b -> FieldLbl a -> b)
-> (forall b a. (b -> a -> b) -> b -> FieldLbl a -> b)
-> (forall a. (a -> a -> a) -> FieldLbl a -> a)
-> (forall a. (a -> a -> a) -> FieldLbl a -> a)
-> (forall a. FieldLbl a -> [a])
-> (forall a. FieldLbl a -> Bool)
-> (forall a. FieldLbl a -> Int)
-> (forall a. Eq a => a -> FieldLbl a -> Bool)
-> (forall a. Ord a => FieldLbl a -> a)
-> (forall a. Ord a => FieldLbl a -> a)
-> (forall a. Num a => FieldLbl a -> a)
-> (forall a. Num a => FieldLbl a -> a)
-> Foldable FieldLbl
forall a. Eq a => a -> FieldLbl a -> Bool
forall a. Num a => FieldLbl a -> a
forall a. Ord a => FieldLbl a -> a
forall m. Monoid m => FieldLbl m -> m
forall a. FieldLbl a -> Bool
forall a. FieldLbl a -> Int
forall a. FieldLbl a -> [a]
forall a. (a -> a -> a) -> FieldLbl a -> a
forall m a. Monoid m => (a -> m) -> FieldLbl a -> m
forall b a. (b -> a -> b) -> b -> FieldLbl a -> b
forall a b. (a -> b -> b) -> b -> FieldLbl 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 :: FieldLbl a -> a
$cproduct :: forall a. Num a => FieldLbl a -> a
sum :: FieldLbl a -> a
$csum :: forall a. Num a => FieldLbl a -> a
minimum :: FieldLbl a -> a
$cminimum :: forall a. Ord a => FieldLbl a -> a
maximum :: FieldLbl a -> a
$cmaximum :: forall a. Ord a => FieldLbl a -> a
elem :: a -> FieldLbl a -> Bool
$celem :: forall a. Eq a => a -> FieldLbl a -> Bool
length :: FieldLbl a -> Int
$clength :: forall a. FieldLbl a -> Int
null :: FieldLbl a -> Bool
$cnull :: forall a. FieldLbl a -> Bool
toList :: FieldLbl a -> [a]
$ctoList :: forall a. FieldLbl a -> [a]
foldl1 :: (a -> a -> a) -> FieldLbl a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> FieldLbl a -> a
foldr1 :: (a -> a -> a) -> FieldLbl a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> FieldLbl a -> a
foldl' :: (b -> a -> b) -> b -> FieldLbl a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> FieldLbl a -> b
foldl :: (b -> a -> b) -> b -> FieldLbl a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> FieldLbl a -> b
foldr' :: (a -> b -> b) -> b -> FieldLbl a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> FieldLbl a -> b
foldr :: (a -> b -> b) -> b -> FieldLbl a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> FieldLbl a -> b
foldMap' :: (a -> m) -> FieldLbl a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> FieldLbl a -> m
foldMap :: (a -> m) -> FieldLbl a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> FieldLbl a -> m
fold :: FieldLbl m -> m
$cfold :: forall m. Monoid m => FieldLbl m -> m
Foldable, Functor FieldLbl
Foldable FieldLbl
Functor FieldLbl
-> Foldable FieldLbl
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FieldLbl a -> f (FieldLbl b))
-> (forall (f :: * -> *) a.
Applicative f =>
FieldLbl (f a) -> f (FieldLbl a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FieldLbl a -> m (FieldLbl b))
-> (forall (m :: * -> *) a.
Monad m =>
FieldLbl (m a) -> m (FieldLbl a))
-> Traversable FieldLbl
(a -> f b) -> FieldLbl a -> f (FieldLbl 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 => FieldLbl (m a) -> m (FieldLbl a)
forall (f :: * -> *) a.
Applicative f =>
FieldLbl (f a) -> f (FieldLbl a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FieldLbl a -> m (FieldLbl b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FieldLbl a -> f (FieldLbl b)
sequence :: FieldLbl (m a) -> m (FieldLbl a)
$csequence :: forall (m :: * -> *) a. Monad m => FieldLbl (m a) -> m (FieldLbl a)
mapM :: (a -> m b) -> FieldLbl a -> m (FieldLbl b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FieldLbl a -> m (FieldLbl b)
sequenceA :: FieldLbl (f a) -> f (FieldLbl a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
FieldLbl (f a) -> f (FieldLbl a)
traverse :: (a -> f b) -> FieldLbl a -> f (FieldLbl b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FieldLbl a -> f (FieldLbl b)
$cp2Traversable :: Foldable FieldLbl
$cp1Traversable :: Functor FieldLbl
Traversable)
deriving instance Data a => Data (FieldLbl a)
instance Outputable a => Outputable (FieldLbl a) where
ppr :: FieldLbl a -> SDoc
ppr FieldLbl a
fl = FieldLabelString -> SDoc
forall a. Outputable a => a -> SDoc
ppr (FieldLbl a -> FieldLabelString
forall a. FieldLbl a -> FieldLabelString
flLabel FieldLbl a
fl) SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr (FieldLbl a -> a
forall a. FieldLbl a -> a
flSelector FieldLbl a
fl))
instance Binary a => Binary (FieldLbl a) where
put_ :: BinHandle -> FieldLbl a -> IO ()
put_ BinHandle
bh (FieldLabel FieldLabelString
aa Bool
ab a
ac) = do
BinHandle -> FieldLabelString -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh FieldLabelString
aa
BinHandle -> Bool -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
ab
BinHandle -> a -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh a
ac
get :: BinHandle -> IO (FieldLbl a)
get BinHandle
bh = do
FieldLabelString
ab <- BinHandle -> IO FieldLabelString
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
Bool
ac <- BinHandle -> IO Bool
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
a
ad <- BinHandle -> IO a
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
FieldLbl a -> IO (FieldLbl a)
forall (m :: * -> *) a. Monad m => a -> m a
return (FieldLabelString -> Bool -> a -> FieldLbl a
forall a. FieldLabelString -> Bool -> a -> FieldLbl a
FieldLabel FieldLabelString
ab Bool
ac a
ad)
mkFieldLabelOccs :: FieldLabelString -> OccName -> Bool -> FieldLbl OccName
mkFieldLabelOccs :: FieldLabelString -> OccName -> Bool -> FieldLbl OccName
mkFieldLabelOccs FieldLabelString
lbl OccName
dc Bool
is_overloaded
= FieldLabel :: forall a. FieldLabelString -> Bool -> a -> FieldLbl a
FieldLabel { flLabel :: FieldLabelString
flLabel = FieldLabelString
lbl, flIsOverloaded :: Bool
flIsOverloaded = Bool
is_overloaded
, flSelector :: OccName
flSelector = OccName
sel_occ }
where
str :: [Char]
str = [Char]
":" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ FieldLabelString -> [Char]
unpackFS FieldLabelString
lbl [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
":" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ OccName -> [Char]
occNameString OccName
dc
sel_occ :: OccName
sel_occ | Bool
is_overloaded = [Char] -> OccName
mkRecFldSelOcc [Char]
str
| Bool
otherwise = FieldLabelString -> OccName
mkVarOccFS FieldLabelString
lbl