{-# 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
/= :: Void -> Void -> Bool
$c/= :: Void -> Void -> Bool
== :: Void -> Void -> Bool
$c== :: 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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Void -> m Void
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Void -> m Void
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Void -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Void -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Void -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Void -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r
gmapT :: (forall b. Data b => b -> b) -> Void -> Void
$cgmapT :: (forall b. Data b => b -> b) -> Void -> Void
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Void)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Void)
dataTypeOf :: Void -> DataType
$cdataTypeOf :: Void -> DataType
toConstr :: Void -> Constr
$ctoConstr :: Void -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Void
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Void
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Void -> c Void
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Void -> c Void
Data    -- ^ @since 4.8.0.0
  , (forall x. Void -> Rep Void x)
-> (forall x. Rep Void x -> Void) -> Generic Void
forall x. Rep Void x -> Void
forall x. Void -> Rep Void x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Void x -> Void
$cfrom :: forall x. Void -> Rep Void x
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
min :: Void -> Void -> Void
$cmin :: Void -> Void -> Void
max :: Void -> Void -> Void
$cmax :: Void -> Void -> Void
>= :: Void -> Void -> Bool
$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
compare :: Void -> Void -> Ordering
$ccompare :: Void -> Void -> Ordering
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
readListPrec :: ReadPrec [Void]
$creadListPrec :: ReadPrec [Void]
readPrec :: ReadPrec Void
$creadPrec :: ReadPrec Void
readList :: ReadS [Void]
$creadList :: ReadS [Void]
readsPrec :: Int -> ReadS Void
$creadsPrec :: Int -> ReadS 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
showList :: [Void] -> ShowS
$cshowList :: [Void] -> ShowS
show :: Void -> String
$cshow :: Void -> String
showsPrec :: Int -> Void -> ShowS
$cshowsPrec :: Int -> 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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Void -> a
forall a. Void -> a
absurd