{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFunctor      #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE Safe               #-}

module Data.Tuple.Only where

import           Control.DeepSeq (NFData (rnf))
import           Data.Data       (Data)
import           Data.Typeable   (Typeable)
import           GHC.Generics    (Generic)

-- | The 1-tuple type or single-value "collection".
--
-- This type is structurally equivalent to the
-- 'Data.Functor.Identity.Identity' type, but its intent is more
-- about serving as the anonymous 1-tuple type missing from Haskell for attaching
-- typeclass instances.
--
-- Parameter usage example:
--
-- @encodeSomething ('Only' (42::Int))@
--
-- Result usage example:
--
-- @xs <- decodeSomething
--forM_ xs $ \\('Only' id) -> {- ... -}@
--
newtype Only a = Only { Only a -> a
fromOnly :: a }
               deriving (Only a -> Only a -> Bool
(Only a -> Only a -> Bool)
-> (Only a -> Only a -> Bool) -> Eq (Only a)
forall a. Eq a => Only a -> Only a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Only a -> Only a -> Bool
$c/= :: forall a. Eq a => Only a -> Only a -> Bool
== :: Only a -> Only a -> Bool
$c== :: forall a. Eq a => Only a -> Only a -> Bool
Eq, Eq (Only a)
Eq (Only a)
-> (Only a -> Only a -> Ordering)
-> (Only a -> Only a -> Bool)
-> (Only a -> Only a -> Bool)
-> (Only a -> Only a -> Bool)
-> (Only a -> Only a -> Bool)
-> (Only a -> Only a -> Only a)
-> (Only a -> Only a -> Only a)
-> Ord (Only a)
Only a -> Only a -> Bool
Only a -> Only a -> Ordering
Only a -> Only a -> Only a
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
forall a. Ord a => Eq (Only a)
forall a. Ord a => Only a -> Only a -> Bool
forall a. Ord a => Only a -> Only a -> Ordering
forall a. Ord a => Only a -> Only a -> Only a
min :: Only a -> Only a -> Only a
$cmin :: forall a. Ord a => Only a -> Only a -> Only a
max :: Only a -> Only a -> Only a
$cmax :: forall a. Ord a => Only a -> Only a -> Only a
>= :: Only a -> Only a -> Bool
$c>= :: forall a. Ord a => Only a -> Only a -> Bool
> :: Only a -> Only a -> Bool
$c> :: forall a. Ord a => Only a -> Only a -> Bool
<= :: Only a -> Only a -> Bool
$c<= :: forall a. Ord a => Only a -> Only a -> Bool
< :: Only a -> Only a -> Bool
$c< :: forall a. Ord a => Only a -> Only a -> Bool
compare :: Only a -> Only a -> Ordering
$ccompare :: forall a. Ord a => Only a -> Only a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Only a)
Ord, ReadPrec [Only a]
ReadPrec (Only a)
Int -> ReadS (Only a)
ReadS [Only a]
(Int -> ReadS (Only a))
-> ReadS [Only a]
-> ReadPrec (Only a)
-> ReadPrec [Only a]
-> Read (Only a)
forall a. Read a => ReadPrec [Only a]
forall a. Read a => ReadPrec (Only a)
forall a. Read a => Int -> ReadS (Only a)
forall a. Read a => ReadS [Only a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Only a]
$creadListPrec :: forall a. Read a => ReadPrec [Only a]
readPrec :: ReadPrec (Only a)
$creadPrec :: forall a. Read a => ReadPrec (Only a)
readList :: ReadS [Only a]
$creadList :: forall a. Read a => ReadS [Only a]
readsPrec :: Int -> ReadS (Only a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Only a)
Read, Int -> Only a -> ShowS
[Only a] -> ShowS
Only a -> String
(Int -> Only a -> ShowS)
-> (Only a -> String) -> ([Only a] -> ShowS) -> Show (Only a)
forall a. Show a => Int -> Only a -> ShowS
forall a. Show a => [Only a] -> ShowS
forall a. Show a => Only a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Only a] -> ShowS
$cshowList :: forall a. Show a => [Only a] -> ShowS
show :: Only a -> String
$cshow :: forall a. Show a => Only a -> String
showsPrec :: Int -> Only a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Only a -> ShowS
Show, (forall x. Only a -> Rep (Only a) x)
-> (forall x. Rep (Only a) x -> Only a) -> Generic (Only a)
forall x. Rep (Only a) x -> Only a
forall x. Only a -> Rep (Only a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Only a) x -> Only a
forall a x. Only a -> Rep (Only a) x
$cto :: forall a x. Rep (Only a) x -> Only a
$cfrom :: forall a x. Only a -> Rep (Only a) x
Generic, a -> Only b -> Only a
(a -> b) -> Only a -> Only b
(forall a b. (a -> b) -> Only a -> Only b)
-> (forall a b. a -> Only b -> Only a) -> Functor Only
forall a b. a -> Only b -> Only a
forall a b. (a -> b) -> Only a -> Only b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Only b -> Only a
$c<$ :: forall a b. a -> Only b -> Only a
fmap :: (a -> b) -> Only a -> Only b
$cfmap :: forall a b. (a -> b) -> Only a -> Only b
Functor, Typeable (Only a)
DataType
Constr
Typeable (Only a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Only a -> c (Only a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Only a))
-> (Only a -> Constr)
-> (Only a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Only a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a)))
-> ((forall b. Data b => b -> b) -> Only a -> Only a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Only a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Only a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Only a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Only a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Only a -> m (Only a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Only a -> m (Only a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Only a -> m (Only a))
-> Data (Only a)
Only a -> DataType
Only a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Only a))
(forall b. Data b => b -> b) -> Only a -> Only a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Only a -> c (Only a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Only a)
forall a. Data a => Typeable (Only a)
forall a. Data a => Only a -> DataType
forall a. Data a => Only a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Only a -> Only a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Only a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> Only a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Only a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Only a -> c (Only a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Only a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only 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) -> Only a -> u
forall u. (forall d. Data d => d -> u) -> Only a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Only a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Only a -> c (Only a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Only a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a))
$cOnly :: Constr
$tOnly :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Only a -> m (Only a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
gmapMp :: (forall d. Data d => d -> m d) -> Only a -> m (Only a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
gmapM :: (forall d. Data d => d -> m d) -> Only a -> m (Only a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Only a -> m (Only a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Only a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Only a -> u
gmapQ :: (forall d. Data d => d -> u) -> Only a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> Only a -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r
gmapT :: (forall b. Data b => b -> b) -> Only a -> Only a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Only a -> Only a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Only a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Only a))
dataTypeOf :: Only a -> DataType
$cdataTypeOf :: forall a. Data a => Only a -> DataType
toConstr :: Only a -> Constr
$ctoConstr :: forall a. Data a => Only a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Only a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Only a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Only a -> c (Only a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Only a -> c (Only a)
$cp1Data :: forall a. Data a => Typeable (Only a)
Data, Typeable)

instance NFData a => NFData (Only a) where
    rnf :: Only a -> ()
rnf = a -> ()
forall a. NFData a => a -> ()
rnf (a -> ()) -> (Only a -> a) -> Only a -> ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Only a -> a
forall a. Only a -> a
fromOnly