{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE EmptyDataDeriving #-}
{-# LANGUAGE Safe #-}

-----------------------------------------------------------------------------
-- |
-- Copyright   :  (C) 2008-2014 Edward Kmett
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
-- Stability   :  provisional
-- Portability :  portable
--
-- A logically uninhabited data type, used to indicate that a given
-- term should not exist.
--
-- @since 4.8.0.0
----------------------------------------------------------------------------
module Data.Void
    ( Void
    , absurd
    , vacuous
    ) where

import Control.Exception
import Data.Data
import Data.Ix
import GHC.Generics
import Data.Semigroup (Semigroup(..), stimesIdempotent)

-- $setup
-- >>> import Prelude

-- | Uninhabited data type
--
-- @since 4.8.0.0
data Void deriving
  ( Void -> Void -> Bool
(Void -> Void -> Bool) -> (Void -> Void -> Bool) -> Eq Void
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Void -> Void -> Bool
== :: Void -> Void -> Bool
$c/= :: Void -> Void -> Bool
/= :: Void -> Void -> Bool
Eq      -- ^ @since 4.8.0.0
  , Typeable Void
Typeable Void
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Void -> c Void)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Void)
-> (Void -> Constr)
-> (Void -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Void))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void))
-> ((forall b. Data b => b -> b) -> Void -> Void)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r)
-> (forall u. (forall d. Data d => d -> u) -> Void -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Void -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Void -> m Void)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Void -> m Void)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Void -> m Void)
-> Data Void
Void -> Constr
Void -> DataType
(forall b. Data b => b -> b) -> Void -> Void
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) -> Void -> u
forall u. (forall d. Data d => d -> u) -> Void -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Void -> m Void
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Void -> m Void
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Void
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Void -> c Void
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Void)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Void -> c Void
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Void -> c Void
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Void
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Void
$ctoConstr :: Void -> Constr
toConstr :: Void -> Constr
$cdataTypeOf :: Void -> DataType
dataTypeOf :: Void -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Void)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Void)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void)
$cgmapT :: (forall b. Data b => b -> b) -> Void -> Void
gmapT :: (forall b. Data b => b -> b) -> Void -> Void
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Void -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Void -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Void -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Void -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Void -> m Void
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Void -> m Void
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Void -> m Void
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Void -> m Void
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Void -> m Void
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Void -> m Void
Data    -- ^ @since 4.8.0.0
  , (forall x. Void -> Rep Void x)
-> (forall x. Rep Void x -> Void) -> Generic Void
forall x. Void -> Rep Void x
forall x. Rep Void x -> Void
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Void -> Rep Void x
from :: forall x. Void -> Rep Void x
$cto :: forall x. Rep Void x -> Void
to :: forall x. Rep Void x -> Void
Generic -- ^ @since 4.8.0.0
  , Eq Void
Eq Void
-> (Void -> Void -> Ordering)
-> (Void -> Void -> Bool)
-> (Void -> Void -> Bool)
-> (Void -> Void -> Bool)
-> (Void -> Void -> Bool)
-> (Void -> Void -> Void)
-> (Void -> Void -> Void)
-> Ord Void
Void -> Void -> Bool
Void -> Void -> Ordering
Void -> Void -> Void
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 :: Void -> Void -> Ordering
compare :: Void -> Void -> Ordering
$c< :: Void -> Void -> Bool
< :: Void -> Void -> Bool
$c<= :: Void -> Void -> Bool
<= :: Void -> Void -> Bool
$c> :: Void -> Void -> Bool
> :: Void -> Void -> Bool
$c>= :: Void -> Void -> Bool
>= :: Void -> Void -> Bool
$cmax :: Void -> Void -> Void
max :: Void -> Void -> Void
$cmin :: Void -> Void -> Void
min :: Void -> Void -> Void
Ord     -- ^ @since 4.8.0.0
  , ReadPrec [Void]
ReadPrec Void
Int -> ReadS Void
ReadS [Void]
(Int -> ReadS Void)
-> ReadS [Void] -> ReadPrec Void -> ReadPrec [Void] -> Read Void
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Void
readsPrec :: Int -> ReadS Void
$creadList :: ReadS [Void]
readList :: ReadS [Void]
$creadPrec :: ReadPrec Void
readPrec :: ReadPrec Void
$creadListPrec :: ReadPrec [Void]
readListPrec :: ReadPrec [Void]
Read    -- ^ Reading a 'Void' value is always a parse error, considering
            -- 'Void' as a data type with no constructors.
            --
            -- @since 4.8.0.0
  , Int -> Void -> ShowS
[Void] -> ShowS
Void -> String
(Int -> Void -> ShowS)
-> (Void -> String) -> ([Void] -> ShowS) -> Show Void
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Void -> ShowS
showsPrec :: Int -> Void -> ShowS
$cshow :: Void -> String
show :: Void -> String
$cshowList :: [Void] -> ShowS
showList :: [Void] -> ShowS
Show    -- ^ @since 4.8.0.0
  )

-- | @since 4.8.0.0
instance Ix Void where
    range :: (Void, Void) -> [Void]
range (Void, Void)
_     = []
    index :: (Void, Void) -> Void -> Int
index (Void, Void)
_     = Void -> Int
forall a. Void -> a
absurd
    inRange :: (Void, Void) -> Void -> Bool
inRange (Void, Void)
_   = Void -> Bool
forall a. Void -> a
absurd
    rangeSize :: (Void, Void) -> Int
rangeSize (Void, Void)
_ = Int
0

-- | @since 4.8.0.0
instance Exception Void

-- | @since 4.9.0.0
instance Semigroup Void where
    Void
a <> :: Void -> Void -> Void
<> Void
_ = Void
a
    stimes :: forall b. Integral b => b -> Void -> Void
stimes = b -> Void -> Void
forall b a. Integral b => b -> a -> a
stimesIdempotent

-- | Since 'Void' values logically don't exist, this witnesses the
-- logical reasoning tool of \"ex falso quodlibet\".
--
-- >>> let x :: Either Void Int; x = Right 5
-- >>> :{
-- case x of
--     Right r -> r
--     Left l  -> absurd l
-- :}
-- 5
--
-- @since 4.8.0.0
absurd :: Void -> a
absurd :: forall a. Void -> a
absurd Void
a = case Void
a of {}

-- | If 'Void' is uninhabited then any 'Functor' that holds only
-- values of type 'Void' is holding no values.
-- It is implemented in terms of @fmap absurd@.
--
-- @since 4.8.0.0
vacuous :: Functor f => f Void -> f a
vacuous :: forall (f :: * -> *) a. Functor f => f Void -> f a
vacuous = (Void -> a) -> f Void -> f a
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Void -> a
forall a. Void -> a
absurd