{-# LANGUAGE DeriveDataTypeable  #-}
{-# LANGUAGE DeriveFoldable      #-}
{-# LANGUAGE DeriveFunctor       #-}
{-# LANGUAGE DeriveGeneric       #-}
{-# LANGUAGE DeriveTraversable   #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE Safe                #-}
{-# LANGUAGE ScopedTypeVariables #-}
----------------------------------------------------------------------------
-- |
-- Module      :  Algebra.Lattice.Wide
-- Copyright   :  (C) 2010-2015 Maximilian Bolingbroke, 2015-2019 Oleg Grenrus
-- License     :  BSD-3-Clause (see the file LICENSE)
--
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
----------------------------------------------------------------------------
module Algebra.Lattice.Wide (
    Wide(..)
  ) where

import Prelude ()
import Prelude.Compat

import Algebra.Lattice
import Algebra.PartialOrd

import Control.DeepSeq       (NFData (..))
import Control.Monad         (ap)
import Data.Data             (Data, Typeable)
import Data.Hashable         (Hashable (..))
import Data.Universe.Class   (Finite (..), Universe (..))
import Data.Universe.Helpers (Natural, Tagged, retag)
import GHC.Generics          (Generic, Generic1)

import qualified Test.QuickCheck as QC

--
-- Wide
--

-- | Graft a distinct top and bottom onto any type.
-- The 'Top' is identity for '/\' and the absorbing element for '\/'.
-- The 'Bottom' is the identity for '\/' and and the absorbing element for '/\'.
-- Two 'Middle' values join to top, unless they are equal.
--
-- <<wide.png>>
--
data Wide a
    = Top
    | Middle a
    | Bottom
  deriving ( Wide a -> Wide a -> Bool
forall a. Eq a => Wide a -> Wide a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Wide a -> Wide a -> Bool
$c/= :: forall a. Eq a => Wide a -> Wide a -> Bool
== :: Wide a -> Wide a -> Bool
$c== :: forall a. Eq a => Wide a -> Wide a -> Bool
Eq, Wide a -> Wide a -> Bool
Wide a -> Wide a -> Ordering
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 (Wide a)
forall a. Ord a => Wide a -> Wide a -> Bool
forall a. Ord a => Wide a -> Wide a -> Ordering
forall a. Ord a => Wide a -> Wide a -> Wide a
min :: Wide a -> Wide a -> Wide a
$cmin :: forall a. Ord a => Wide a -> Wide a -> Wide a
max :: Wide a -> Wide a -> Wide a
$cmax :: forall a. Ord a => Wide a -> Wide a -> Wide a
>= :: Wide a -> Wide a -> Bool
$c>= :: forall a. Ord a => Wide a -> Wide a -> Bool
> :: Wide a -> Wide a -> Bool
$c> :: forall a. Ord a => Wide a -> Wide a -> Bool
<= :: Wide a -> Wide a -> Bool
$c<= :: forall a. Ord a => Wide a -> Wide a -> Bool
< :: Wide a -> Wide a -> Bool
$c< :: forall a. Ord a => Wide a -> Wide a -> Bool
compare :: Wide a -> Wide a -> Ordering
$ccompare :: forall a. Ord a => Wide a -> Wide a -> Ordering
Ord, Int -> Wide a -> ShowS
forall a. Show a => Int -> Wide a -> ShowS
forall a. Show a => [Wide a] -> ShowS
forall a. Show a => Wide a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Wide a] -> ShowS
$cshowList :: forall a. Show a => [Wide a] -> ShowS
show :: Wide a -> String
$cshow :: forall a. Show a => Wide a -> String
showsPrec :: Int -> Wide a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Wide a -> ShowS
Show, ReadPrec [Wide a]
ReadPrec (Wide a)
ReadS [Wide a]
forall a. Read a => ReadPrec [Wide a]
forall a. Read a => ReadPrec (Wide a)
forall a. Read a => Int -> ReadS (Wide a)
forall a. Read a => ReadS [Wide a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Wide a]
$creadListPrec :: forall a. Read a => ReadPrec [Wide a]
readPrec :: ReadPrec (Wide a)
$creadPrec :: forall a. Read a => ReadPrec (Wide a)
readList :: ReadS [Wide a]
$creadList :: forall a. Read a => ReadS [Wide a]
readsPrec :: Int -> ReadS (Wide a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Wide a)
Read, Wide a -> DataType
Wide a -> Constr
forall {a}. Data a => Typeable (Wide a)
forall a. Data a => Wide a -> DataType
forall a. Data a => Wide a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Wide a -> Wide a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Wide a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> Wide a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Wide a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wide a -> c (Wide a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Wide a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Wide 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 (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Wide a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wide a -> c (Wide a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Wide a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Wide a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Wide a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Wide a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> Wide a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
gmapT :: (forall b. Data b => b -> b) -> Wide a -> Wide a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Wide a -> Wide a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Wide a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Wide a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Wide a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Wide a))
dataTypeOf :: Wide a -> DataType
$cdataTypeOf :: forall a. Data a => Wide a -> DataType
toConstr :: Wide a -> Constr
$ctoConstr :: forall a. Data a => Wide a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Wide a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Wide a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wide a -> c (Wide a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wide a -> c (Wide a)
Data, Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Wide a) x -> Wide a
forall a x. Wide a -> Rep (Wide a) x
$cto :: forall a x. Rep (Wide a) x -> Wide a
$cfrom :: forall a x. Wide a -> Rep (Wide a) x
Generic, forall a b. a -> Wide b -> Wide a
forall a b. (a -> b) -> Wide a -> Wide b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Wide b -> Wide a
$c<$ :: forall a b. a -> Wide b -> Wide a
fmap :: forall a b. (a -> b) -> Wide a -> Wide b
$cfmap :: forall a b. (a -> b) -> Wide a -> Wide b
Functor, forall a. Eq a => a -> Wide a -> Bool
forall a. Num a => Wide a -> a
forall a. Ord a => Wide a -> a
forall m. Monoid m => Wide m -> m
forall a. Wide a -> Bool
forall a. Wide a -> Int
forall a. Wide a -> [a]
forall a. (a -> a -> a) -> Wide a -> a
forall m a. Monoid m => (a -> m) -> Wide a -> m
forall b a. (b -> a -> b) -> b -> Wide a -> b
forall a b. (a -> b -> b) -> b -> Wide 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 :: forall a. Num a => Wide a -> a
$cproduct :: forall a. Num a => Wide a -> a
sum :: forall a. Num a => Wide a -> a
$csum :: forall a. Num a => Wide a -> a
minimum :: forall a. Ord a => Wide a -> a
$cminimum :: forall a. Ord a => Wide a -> a
maximum :: forall a. Ord a => Wide a -> a
$cmaximum :: forall a. Ord a => Wide a -> a
elem :: forall a. Eq a => a -> Wide a -> Bool
$celem :: forall a. Eq a => a -> Wide a -> Bool
length :: forall a. Wide a -> Int
$clength :: forall a. Wide a -> Int
null :: forall a. Wide a -> Bool
$cnull :: forall a. Wide a -> Bool
toList :: forall a. Wide a -> [a]
$ctoList :: forall a. Wide a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Wide a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Wide a -> a
foldr1 :: forall a. (a -> a -> a) -> Wide a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Wide a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Wide a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Wide a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Wide a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Wide a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Wide a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Wide a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Wide a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Wide a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Wide a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Wide a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Wide a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Wide a -> m
fold :: forall m. Monoid m => Wide m -> m
$cfold :: forall m. Monoid m => Wide m -> m
Foldable, Functor Wide
Foldable Wide
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 => Wide (m a) -> m (Wide a)
forall (f :: * -> *) a. Applicative f => Wide (f a) -> f (Wide a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Wide a -> m (Wide b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Wide a -> f (Wide b)
sequence :: forall (m :: * -> *) a. Monad m => Wide (m a) -> m (Wide a)
$csequence :: forall (m :: * -> *) a. Monad m => Wide (m a) -> m (Wide a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Wide a -> m (Wide b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Wide a -> m (Wide b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Wide (f a) -> f (Wide a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Wide (f a) -> f (Wide a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Wide a -> f (Wide b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Wide a -> f (Wide b)
Traversable
           , forall a. Rep1 Wide a -> Wide a
forall a. Wide a -> Rep1 Wide a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 Wide a -> Wide a
$cfrom1 :: forall a. Wide a -> Rep1 Wide a
Generic1
           )

instance Applicative Wide where
  pure :: forall a. a -> Wide a
pure = forall (m :: * -> *) a. Monad m => a -> m a
return
  <*> :: forall a b. Wide (a -> b) -> Wide a -> Wide b
(<*>) = forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

instance Monad Wide where
  return :: forall a. a -> Wide a
return       = forall a. a -> Wide a
Middle
  Wide a
Top >>= :: forall a b. Wide a -> (a -> Wide b) -> Wide b
>>= a -> Wide b
_    = forall a. Wide a
Top
  Wide a
Bottom >>= a -> Wide b
_ = forall a. Wide a
Bottom
  Middle a
x >>= a -> Wide b
f = a -> Wide b
f a
x

instance NFData a => NFData (Wide a) where
  rnf :: Wide a -> ()
rnf Wide a
Top      = ()
  rnf Wide a
Bottom   = ()
  rnf (Middle a
a) = forall a. NFData a => a -> ()
rnf a
a

instance Hashable a => Hashable (Wide a)

instance Eq a => Lattice (Wide a) where
  Wide a
Top      \/ :: Wide a -> Wide a -> Wide a
\/ Wide a
_        = forall a. Wide a
Top
  Wide a
Bottom   \/ Wide a
x        = Wide a
x
  Middle a
_ \/ Wide a
Top      = forall a. Wide a
Top
  Middle a
x \/ Wide a
Bottom   = forall a. a -> Wide a
Middle a
x
  Middle a
x \/ Middle a
y = if a
x forall a. Eq a => a -> a -> Bool
== a
y then forall a. a -> Wide a
Middle a
x else forall a. Wide a
Top

  Wide a
Bottom   /\ :: Wide a -> Wide a -> Wide a
/\ Wide a
_        = forall a. Wide a
Bottom
  Wide a
Top      /\ Wide a
x        = Wide a
x
  Middle a
_ /\ Wide a
Bottom   = forall a. Wide a
Bottom
  Middle a
x /\ Wide a
Top      = forall a. a -> Wide a
Middle a
x
  Middle a
x /\ Middle a
y = if a
x forall a. Eq a => a -> a -> Bool
== a
y then forall a. a -> Wide a
Middle a
x else forall a. Wide a
Bottom

instance Eq a => BoundedJoinSemiLattice (Wide a) where
  bottom :: Wide a
bottom = forall a. Wide a
Bottom

instance Eq a => BoundedMeetSemiLattice (Wide a) where
  top :: Wide a
top = forall a. Wide a
Top

instance Eq a => PartialOrd (Wide a) where
  leq :: Wide a -> Wide a -> Bool
leq Wide a
Bottom Wide a
_              = Bool
True
  leq Wide a
Top Wide a
Bottom            = Bool
False
  leq Wide a
Top (Middle a
_)        = Bool
False
  leq Wide a
Top Wide a
Top               = Bool
True
  leq (Middle a
_) Wide a
Bottom     = Bool
False
  leq (Middle a
_) Wide a
Top        = Bool
True
  leq (Middle a
x) (Middle a
y) = a
x forall a. Eq a => a -> a -> Bool
== a
y

  comparable :: Wide a -> Wide a -> Bool
comparable Wide a
Bottom Wide a
_              = Bool
True
  comparable Wide a
Top Wide a
_                 = Bool
True
  comparable (Middle a
_) Wide a
Bottom     = Bool
True
  comparable (Middle a
_) Wide a
Top        = Bool
True
  comparable (Middle a
x) (Middle a
y) = a
x forall a. Eq a => a -> a -> Bool
== a
y

instance Universe a => Universe (Wide a) where
    universe :: [Wide a]
universe = forall a. Wide a
Top forall a. a -> [a] -> [a]
: forall a. Wide a
Bottom forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Wide a
Middle forall a. Universe a => [a]
universe
instance Finite a => Finite (Wide a) where
    universeF :: [Wide a]
universeF = forall a. Wide a
Top forall a. a -> [a] -> [a]
: forall a. Wide a
Bottom forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Wide a
Middle forall a. Finite a => [a]
universeF
    cardinality :: Tagged (Wide a) Natural
cardinality = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Natural
2 forall a. Num a => a -> a -> a
+) (forall {k1} {k2} (s :: k1) b (t :: k2). Tagged s b -> Tagged t b
retag (forall a. Finite a => Tagged a Natural
cardinality :: Tagged a Natural))

instance QC.Arbitrary a => QC.Arbitrary (Wide a) where
    arbitrary :: Gen (Wide a)
arbitrary = forall a. [(Int, Gen a)] -> Gen a
QC.frequency
        [ (Int
1, forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Wide a
Top)
        , (Int
1, forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Wide a
Bottom)
        , (Int
9, forall a. a -> Wide a
Middle forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
QC.arbitrary)
        ]

    shrink :: Wide a -> [Wide a]
shrink Wide a
Top        = []
    shrink Wide a
Bottom     = []
    shrink (Middle a
x) = forall a. Wide a
Top forall a. a -> [a] -> [a]
: forall a. Wide a
Bottom forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a. a -> Wide a
Middle (forall a. Arbitrary a => a -> [a]
QC.shrink a
x)

instance QC.CoArbitrary a => QC.CoArbitrary (Wide a) where
    coarbitrary :: forall b. Wide a -> Gen b -> Gen b
coarbitrary Wide a
Top        = forall n a. Integral n => n -> Gen a -> Gen a
QC.variant (Int
0 :: Int)
    coarbitrary Wide a
Bottom     = forall n a. Integral n => n -> Gen a -> Gen a
QC.variant (Int
0 :: Int)
    coarbitrary (Middle a
x) = forall n a. Integral n => n -> Gen a -> Gen a
QC.variant (Int
0 :: Int) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. CoArbitrary a => a -> Gen b -> Gen b
QC.coarbitrary a
x

instance QC.Function a => QC.Function (Wide a) where
    function :: forall b. (Wide a -> b) -> Wide a :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
QC.functionMap forall {b}. Wide b -> Either Bool b
fromWide forall {a}. Either Bool a -> Wide a
toWide where
        fromWide :: Wide b -> Either Bool b
fromWide Wide b
Top        = forall a b. a -> Either a b
Left Bool
True
        fromWide Wide b
Bottom     = forall a b. a -> Either a b
Left Bool
False
        fromWide (Middle b
x) = forall a b. b -> Either a b
Right b
x

        toWide :: Either Bool a -> Wide a
toWide (Left Bool
True)  = forall a. Wide a
Top
        toWide (Left Bool
False) = forall a. Wide a
Bottom
        toWide (Right a
x)    = forall a. a -> Wide a
Middle a
x