{-# 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
(Wide a -> Wide a -> Bool)
-> (Wide a -> Wide a -> Bool) -> Eq (Wide a)
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, Eq (Wide a)
Eq (Wide a)
-> (Wide a -> Wide a -> Ordering)
-> (Wide a -> Wide a -> Bool)
-> (Wide a -> Wide a -> Bool)
-> (Wide a -> Wide a -> Bool)
-> (Wide a -> Wide a -> Bool)
-> (Wide a -> Wide a -> Wide a)
-> (Wide a -> Wide a -> Wide a)
-> Ord (Wide a)
Wide a -> Wide a -> Bool
Wide a -> Wide a -> Ordering
Wide a -> Wide a -> Wide 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 (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
$cp1Ord :: forall a. Ord a => Eq (Wide a)
Ord, Int -> Wide a -> ShowS
[Wide a] -> ShowS
Wide a -> String
(Int -> Wide a -> ShowS)
-> (Wide a -> String) -> ([Wide a] -> ShowS) -> Show (Wide a)
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)
Int -> ReadS (Wide a)
ReadS [Wide a]
(Int -> ReadS (Wide a))
-> ReadS [Wide a]
-> ReadPrec (Wide a)
-> ReadPrec [Wide a]
-> Read (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, Typeable (Wide a)
DataType
Constr
Typeable (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 (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Wide a))
-> (Wide a -> Constr)
-> (Wide a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Wide a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Wide a)))
-> ((forall b. Data b => b -> b) -> Wide a -> Wide a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Wide a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Wide a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Wide a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Wide a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Wide a -> m (Wide a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Wide a -> m (Wide a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Wide a -> m (Wide a))
-> Data (Wide a)
Wide a -> DataType
Wide a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Wide a))
(forall b. Data b => b -> b) -> Wide a -> Wide a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wide a -> c (Wide a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Wide a)
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 u. Int -> (forall d. Data d => d -> u) -> Wide a -> u
forall u. (forall d. Data d => d -> u) -> Wide a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wide a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wide a -> m (Wide 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))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Wide a))
$cBottom :: Constr
$cMiddle :: Constr
$cTop :: Constr
$tWide :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> Wide a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> Wide a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (Wide a)
Data, Typeable, (forall x. Wide a -> Rep (Wide a) x)
-> (forall x. Rep (Wide a) x -> Wide a) -> Generic (Wide a)
forall x. Rep (Wide a) x -> Wide a
forall x. Wide a -> Rep (Wide a) x
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, a -> Wide b -> Wide a
(a -> b) -> Wide a -> Wide b
(forall a b. (a -> b) -> Wide a -> Wide b)
-> (forall a b. a -> Wide b -> Wide a) -> Functor Wide
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
<$ :: a -> Wide b -> Wide a
$c<$ :: forall a b. a -> Wide b -> Wide a
fmap :: (a -> b) -> Wide a -> Wide b
$cfmap :: forall a b. (a -> b) -> Wide a -> Wide b
Functor, Wide a -> Bool
(a -> m) -> Wide a -> m
(a -> b -> b) -> b -> Wide a -> b
(forall m. Monoid m => Wide m -> m)
-> (forall m a. Monoid m => (a -> m) -> Wide a -> m)
-> (forall m a. Monoid m => (a -> m) -> Wide a -> m)
-> (forall a b. (a -> b -> b) -> b -> Wide a -> b)
-> (forall a b. (a -> b -> b) -> b -> Wide a -> b)
-> (forall b a. (b -> a -> b) -> b -> Wide a -> b)
-> (forall b a. (b -> a -> b) -> b -> Wide a -> b)
-> (forall a. (a -> a -> a) -> Wide a -> a)
-> (forall a. (a -> a -> a) -> Wide a -> a)
-> (forall a. Wide a -> [a])
-> (forall a. Wide a -> Bool)
-> (forall a. Wide a -> Int)
-> (forall a. Eq a => a -> Wide a -> Bool)
-> (forall a. Ord a => Wide a -> a)
-> (forall a. Ord a => Wide a -> a)
-> (forall a. Num a => Wide a -> a)
-> (forall a. Num a => Wide a -> a)
-> Foldable Wide
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 :: Wide a -> a
$cproduct :: forall a. Num a => Wide a -> a
sum :: Wide a -> a
$csum :: forall a. Num a => Wide a -> a
minimum :: Wide a -> a
$cminimum :: forall a. Ord a => Wide a -> a
maximum :: Wide a -> a
$cmaximum :: forall a. Ord a => Wide a -> a
elem :: a -> Wide a -> Bool
$celem :: forall a. Eq a => a -> Wide a -> Bool
length :: Wide a -> Int
$clength :: forall a. Wide a -> Int
null :: Wide a -> Bool
$cnull :: forall a. Wide a -> Bool
toList :: Wide a -> [a]
$ctoList :: forall a. Wide a -> [a]
foldl1 :: (a -> a -> a) -> Wide a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Wide a -> a
foldr1 :: (a -> a -> a) -> Wide a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Wide a -> a
foldl' :: (b -> a -> b) -> b -> Wide a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Wide a -> b
foldl :: (b -> a -> b) -> b -> Wide a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Wide a -> b
foldr' :: (a -> b -> b) -> b -> Wide a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Wide a -> b
foldr :: (a -> b -> b) -> b -> Wide a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Wide a -> b
foldMap' :: (a -> m) -> Wide a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Wide a -> m
foldMap :: (a -> m) -> Wide a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Wide a -> m
fold :: Wide m -> m
$cfold :: forall m. Monoid m => Wide m -> m
Foldable, Functor Wide
Foldable Wide
Functor Wide
-> Foldable Wide
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Wide a -> f (Wide b))
-> (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 (m :: * -> *) a. Monad m => Wide (m a) -> m (Wide a))
-> Traversable Wide
(a -> f b) -> Wide a -> f (Wide b)
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 :: Wide (m a) -> m (Wide a)
$csequence :: forall (m :: * -> *) a. Monad m => Wide (m a) -> m (Wide a)
mapM :: (a -> m b) -> Wide a -> m (Wide b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Wide a -> m (Wide b)
sequenceA :: Wide (f a) -> f (Wide a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Wide (f a) -> f (Wide a)
traverse :: (a -> f b) -> Wide a -> f (Wide b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Wide a -> f (Wide b)
$cp2Traversable :: Foldable Wide
$cp1Traversable :: Functor Wide
Traversable
           , (forall a. Wide a -> Rep1 Wide a)
-> (forall a. Rep1 Wide a -> Wide a) -> Generic1 Wide
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 :: a -> Wide a
pure = a -> Wide a
forall (m :: * -> *) a. Monad m => a -> m a
return
  <*> :: Wide (a -> b) -> Wide a -> Wide 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 :: a -> Wide a
return       = a -> Wide a
forall a. a -> Wide a
Middle
  Wide a
Top >>= :: Wide a -> (a -> Wide b) -> Wide b
>>= a -> Wide b
_    = Wide b
forall a. Wide a
Top
  Wide a
Bottom >>= a -> Wide b
_ = 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) = 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
_        = Wide a
forall a. Wide a
Top
  Wide a
Bottom   \/ Wide a
x        = Wide a
x
  Middle a
_ \/ Wide a
Top      = Wide a
forall a. Wide a
Top
  Middle a
x \/ Wide a
Bottom   = a -> Wide a
forall a. a -> Wide a
Middle a
x
  Middle a
x \/ Middle a
y = if a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y then a -> Wide a
forall a. a -> Wide a
Middle a
x else Wide a
forall a. Wide a
Top

  Wide a
Bottom   /\ :: Wide a -> 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   = Wide a
forall a. Wide a
Bottom
  Middle a
x /\ Wide a
Top      = a -> Wide a
forall a. a -> Wide a
Middle a
x
  Middle a
x /\ Middle a
y = if a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y then a -> Wide a
forall a. a -> Wide a
Middle a
x else Wide a
forall a. Wide a
Bottom

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

instance Eq a => BoundedMeetSemiLattice (Wide a) where
  top :: Wide a
top = Wide a
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 a -> a -> Bool
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 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y

instance Universe a => Universe (Wide a) where
    universe :: [Wide a]
universe = Wide a
forall a. Wide a
Top Wide a -> [Wide a] -> [Wide a]
forall a. a -> [a] -> [a]
: Wide a
forall a. Wide a
Bottom Wide a -> [Wide a] -> [Wide a]
forall a. a -> [a] -> [a]
: (a -> Wide a) -> [a] -> [Wide a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Wide a
forall a. a -> Wide a
Middle [a]
forall a. Universe a => [a]
universe
instance Finite a => Finite (Wide a) where
    universeF :: [Wide a]
universeF = Wide a
forall a. Wide a
Top Wide a -> [Wide a] -> [Wide a]
forall a. a -> [a] -> [a]
: Wide a
forall a. Wide a
Bottom Wide a -> [Wide a] -> [Wide a]
forall a. a -> [a] -> [a]
: (a -> Wide a) -> [a] -> [Wide a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Wide a
forall a. a -> Wide a
Middle [a]
forall a. Finite a => [a]
universeF
    cardinality :: Tagged (Wide a) Natural
cardinality = (Natural -> Natural)
-> Tagged (Wide a) Natural -> Tagged (Wide a) Natural
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Natural
2 Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+) (Tagged a Natural -> Tagged (Wide a) Natural
forall k1 k2 (s :: k1) b (t :: k2). Tagged s b -> Tagged t b
retag (Tagged a Natural
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 = [(Int, Gen (Wide a))] -> Gen (Wide a)
forall a. [(Int, Gen a)] -> Gen a
QC.frequency
        [ (Int
1, Wide a -> Gen (Wide a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Wide a
forall a. Wide a
Top)
        , (Int
1, Wide a -> Gen (Wide a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Wide a
forall a. Wide a
Bottom)
        , (Int
9, a -> Wide a
forall a. a -> Wide a
Middle (a -> Wide a) -> Gen a -> Gen (Wide a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
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) = Wide a
forall a. Wide a
Top Wide a -> [Wide a] -> [Wide a]
forall a. a -> [a] -> [a]
: Wide a
forall a. Wide a
Bottom Wide a -> [Wide a] -> [Wide a]
forall a. a -> [a] -> [a]
: (a -> Wide a) -> [a] -> [Wide a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Wide a
forall a. a -> Wide a
Middle (a -> [a]
forall a. Arbitrary a => a -> [a]
QC.shrink a
x)

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

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

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