{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}

module Data.PQueue.Internals.Down where

import Control.DeepSeq (NFData(rnf))
import Data.Foldable (Foldable (..))

#if __GLASGOW_HASKELL__
import Data.Data (Data)
#endif

newtype Down a = Down { Down a -> a
unDown :: a }
#if __GLASGOW_HASKELL__
  deriving (Down a -> Down a -> Bool
(Down a -> Down a -> Bool)
-> (Down a -> Down a -> Bool) -> Eq (Down a)
forall a. Eq a => Down a -> Down a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Down a -> Down a -> Bool
$c/= :: forall a. Eq a => Down a -> Down a -> Bool
== :: Down a -> Down a -> Bool
$c== :: forall a. Eq a => Down a -> Down a -> Bool
Eq, Typeable (Down a)
DataType
Constr
Typeable (Down a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Down a -> c (Down a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Down a))
-> (Down a -> Constr)
-> (Down a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Down a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Down a)))
-> ((forall b. Data b => b -> b) -> Down a -> Down a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Down a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Down a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Down a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Down a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Down a -> m (Down a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Down a -> m (Down a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Down a -> m (Down a))
-> Data (Down a)
Down a -> DataType
Down a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Down a))
(forall b. Data b => b -> b) -> Down a -> Down a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Down a -> c (Down a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Down a)
forall a. Data a => Typeable (Down a)
forall a. Data a => Down a -> DataType
forall a. Data a => Down a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Down a -> Down a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Down a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> Down a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Down a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Down a -> c (Down a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Down a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Down a))
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) -> Down a -> u
forall u. (forall d. Data d => d -> u) -> Down a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Down a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Down a -> c (Down a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Down a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Down a))
$cDown :: Constr
$tDown :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Down a -> m (Down a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
gmapMp :: (forall d. Data d => d -> m d) -> Down a -> m (Down a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
gmapM :: (forall d. Data d => d -> m d) -> Down a -> m (Down a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Down a -> m (Down a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Down a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Down a -> u
gmapQ :: (forall d. Data d => d -> u) -> Down a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> Down a -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Down a -> r
gmapT :: (forall b. Data b => b -> b) -> Down a -> Down a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Down a -> Down a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Down a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Down a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Down a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Down a))
dataTypeOf :: Down a -> DataType
$cdataTypeOf :: forall a. Data a => Down a -> DataType
toConstr :: Down a -> Constr
$ctoConstr :: forall a. Data a => Down a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Down a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Down a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Down a -> c (Down a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Down a -> c (Down a)
$cp1Data :: forall a. Data a => Typeable (Down a)
Data)
#else
  deriving (Eq)
#endif


instance NFData a => NFData (Down a) where
  rnf :: Down a -> ()
rnf (Down a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

instance Ord a => Ord (Down a) where
  Down a
a compare :: Down a -> Down a -> Ordering
`compare` Down a
b = a
b a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` a
a
  Down a
a <= :: Down a -> Down a -> Bool
<= Down a
b = a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
a

instance Functor Down where
  fmap :: (a -> b) -> Down a -> Down b
fmap a -> b
f (Down a
a) = b -> Down b
forall a. a -> Down a
Down (a -> b
f a
a)

instance Foldable Down where
  foldr :: (a -> b -> b) -> b -> Down a -> b
foldr a -> b -> b
f b
z (Down a
a) = a
a a -> b -> b
`f` b
z
  foldl :: (b -> a -> b) -> b -> Down a -> b
foldl b -> a -> b
f b
z (Down a
a) = b
z b -> a -> b
`f` a
a
  foldl' :: (b -> a -> b) -> b -> Down a -> b
foldl' b -> a -> b
f !b
z (Down a
a) = b
z b -> a -> b
`f` a
a