{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.PartialSemigroup
(
PartialSemigroup (..)
, AppendLeft (..)
, AppendRight (..)
, groupAndConcat
, partialConcat
, partialConcat1
, partialZip
, partialZip1
, Total (..)
, Partial (..)
, One (..)
, AtMostOne (..)
) where
import Control.Applicative (ZipList (..), (<$>), (<*>))
import Control.Monad ((>>=))
import Data.Either (Either (..))
import Data.Function ((.))
import Data.Functor.Identity (Identity (..))
import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
import Data.Maybe (Maybe (..))
import Data.Monoid (Monoid (..), Product (..), Sum (..))
import Data.Semigroup (Semigroup (..))
import Prelude (Eq, Num (..), Ord, Read, Show)
infixr 6 <>?
class PartialSemigroup a
where
(<>?) :: a -> a -> Maybe a
instance PartialSemigroup ()
where
() <>? :: () -> () -> Maybe ()
<>? () = () -> Maybe ()
forall a. a -> Maybe a
Just ()
instance PartialSemigroup [a]
where
[a]
x <>? :: [a] -> [a] -> Maybe [a]
<>? [a]
y = [a] -> Maybe [a]
forall a. a -> Maybe a
Just ([a]
x [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> [a]
y)
instance Num a => PartialSemigroup (Sum a)
where
Sum a
x <>? :: Sum a -> Sum a -> Maybe (Sum a)
<>? Sum a
y = Sum a -> Maybe (Sum a)
forall a. a -> Maybe a
Just (Sum a
x Sum a -> Sum a -> Sum a
forall a. Semigroup a => a -> a -> a
<> Sum a
y)
instance Num a => PartialSemigroup (Product a)
where
Product a
x <>? :: Product a -> Product a -> Maybe (Product a)
<>? Product a
y = Product a -> Maybe (Product a)
forall a. a -> Maybe a
Just (Product a
x Product a -> Product a -> Product a
forall a. Semigroup a => a -> a -> a
<> Product a
y)
instance PartialSemigroup a => PartialSemigroup (Identity a)
where
Identity a
x <>? :: Identity a -> Identity a -> Maybe (Identity a)
<>? Identity a
y = a -> Identity a
forall a. a -> Identity a
Identity (a -> Identity a) -> Maybe a -> Maybe (Identity a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y)
instance (PartialSemigroup a, PartialSemigroup b) =>
PartialSemigroup (Either a b)
where
Left a
x <>? :: Either a b -> Either a b -> Maybe (Either a b)
<>? Left a
y = a -> Either a b
forall a b. a -> Either a b
Left (a -> Either a b) -> Maybe a -> Maybe (Either a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y)
Right b
x <>? Right b
y = b -> Either a b
forall a b. b -> Either a b
Right (b -> Either a b) -> Maybe b -> Maybe (Either a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (b
x b -> b -> Maybe b
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? b
y)
Either a b
_ <>? Either a b
_ = Maybe (Either a b)
forall a. Maybe a
Nothing
instance (PartialSemigroup a, PartialSemigroup b) => PartialSemigroup (a, b)
where
(a
a, b
b) <>? :: (a, b) -> (a, b) -> Maybe (a, b)
<>? (a
a', b
b') = (,) (a -> b -> (a, b)) -> Maybe a -> Maybe (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
a a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
a')
Maybe (b -> (a, b)) -> Maybe b -> Maybe (a, b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (b
b b -> b -> Maybe b
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? b
b')
instance (PartialSemigroup a, PartialSemigroup b, PartialSemigroup c) =>
PartialSemigroup (a, b, c)
where
(a
a, b
b, c
c) <>? :: (a, b, c) -> (a, b, c) -> Maybe (a, b, c)
<>? (a
a', b
b', c
c') = (,,) (a -> b -> c -> (a, b, c))
-> Maybe a -> Maybe (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
a a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
a')
Maybe (b -> c -> (a, b, c)) -> Maybe b -> Maybe (c -> (a, b, c))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (b
b b -> b -> Maybe b
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? b
b')
Maybe (c -> (a, b, c)) -> Maybe c -> Maybe (a, b, c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (c
c c -> c -> Maybe c
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? c
c')
groupAndConcat :: PartialSemigroup a => [a] -> [a]
groupAndConcat :: [a] -> [a]
groupAndConcat [] = []
groupAndConcat [a
x] = [a
x]
groupAndConcat (a
x : a
y : [a]
zs) =
case a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y of
Maybe a
Nothing -> a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
forall a. PartialSemigroup a => [a] -> [a]
groupAndConcat (a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs)
Just a
a -> [a] -> [a]
forall a. PartialSemigroup a => [a] -> [a]
groupAndConcat (a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs)
partialConcat :: PartialSemigroup a => [a] -> Maybe a
partialConcat :: [a] -> Maybe a
partialConcat [a]
x =
[a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [a]
x Maybe (NonEmpty a) -> (NonEmpty a -> Maybe a) -> Maybe a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NonEmpty a -> Maybe a
forall a. PartialSemigroup a => NonEmpty a -> Maybe a
partialConcat1
partialConcat1 :: PartialSemigroup a => NonEmpty a -> Maybe a
partialConcat1 :: NonEmpty a -> Maybe a
partialConcat1 (a
x :| []) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
partialConcat1 (a
x :| (a
y : [a]
zs)) =
do
a
a <- a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y
NonEmpty a -> Maybe a
forall a. PartialSemigroup a => NonEmpty a -> Maybe a
partialConcat1 (a
a a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
zs)
partialZip :: PartialSemigroup a => [a] -> [a] -> Maybe [a]
partialZip :: [a] -> [a] -> Maybe [a]
partialZip [] [] = [a] -> Maybe [a]
forall a. a -> Maybe a
Just []
partialZip [] [a]
_ = Maybe [a]
forall a. Maybe a
Nothing
partialZip [a]
_ [] = Maybe [a]
forall a. Maybe a
Nothing
partialZip (a
x:[a]
xs) (a
y:[a]
ys) =
(:) (a -> [a] -> [a]) -> Maybe a -> Maybe ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y) Maybe ([a] -> [a]) -> Maybe [a] -> Maybe [a]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [a] -> [a] -> Maybe [a]
forall a. PartialSemigroup a => [a] -> [a] -> Maybe [a]
partialZip [a]
xs [a]
ys
partialZip1 :: PartialSemigroup a
=> NonEmpty a -> NonEmpty a -> Maybe (NonEmpty a)
partialZip1 :: NonEmpty a -> NonEmpty a -> Maybe (NonEmpty a)
partialZip1 (a
x :| [a]
xs) (a
y :| [a]
ys) =
a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
(:|) (a -> [a] -> NonEmpty a) -> Maybe a -> Maybe ([a] -> NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y) Maybe ([a] -> NonEmpty a) -> Maybe [a] -> Maybe (NonEmpty a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [a] -> [a] -> Maybe [a]
forall a. PartialSemigroup a => [a] -> [a] -> Maybe [a]
partialZip [a]
xs [a]
ys
instance PartialSemigroup a => PartialSemigroup (ZipList a)
where
ZipList [a]
x <>? :: ZipList a -> ZipList a -> Maybe (ZipList a)
<>? ZipList [a]
y = [a] -> ZipList a
forall a. [a] -> ZipList a
ZipList ([a] -> ZipList a) -> Maybe [a] -> Maybe (ZipList a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> [a] -> Maybe [a]
forall a. PartialSemigroup a => [a] -> [a] -> Maybe [a]
partialZip [a]
x [a]
y
newtype Partial a = Partial { Partial a -> Maybe a
unPartial :: Maybe a }
deriving (Partial a -> Partial a -> Bool
(Partial a -> Partial a -> Bool)
-> (Partial a -> Partial a -> Bool) -> Eq (Partial a)
forall a. Eq a => Partial a -> Partial a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Partial a -> Partial a -> Bool
$c/= :: forall a. Eq a => Partial a -> Partial a -> Bool
== :: Partial a -> Partial a -> Bool
$c== :: forall a. Eq a => Partial a -> Partial a -> Bool
Eq, Eq (Partial a)
Eq (Partial a)
-> (Partial a -> Partial a -> Ordering)
-> (Partial a -> Partial a -> Bool)
-> (Partial a -> Partial a -> Bool)
-> (Partial a -> Partial a -> Bool)
-> (Partial a -> Partial a -> Bool)
-> (Partial a -> Partial a -> Partial a)
-> (Partial a -> Partial a -> Partial a)
-> Ord (Partial a)
Partial a -> Partial a -> Bool
Partial a -> Partial a -> Ordering
Partial a -> Partial a -> Partial 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 (Partial a)
forall a. Ord a => Partial a -> Partial a -> Bool
forall a. Ord a => Partial a -> Partial a -> Ordering
forall a. Ord a => Partial a -> Partial a -> Partial a
min :: Partial a -> Partial a -> Partial a
$cmin :: forall a. Ord a => Partial a -> Partial a -> Partial a
max :: Partial a -> Partial a -> Partial a
$cmax :: forall a. Ord a => Partial a -> Partial a -> Partial a
>= :: Partial a -> Partial a -> Bool
$c>= :: forall a. Ord a => Partial a -> Partial a -> Bool
> :: Partial a -> Partial a -> Bool
$c> :: forall a. Ord a => Partial a -> Partial a -> Bool
<= :: Partial a -> Partial a -> Bool
$c<= :: forall a. Ord a => Partial a -> Partial a -> Bool
< :: Partial a -> Partial a -> Bool
$c< :: forall a. Ord a => Partial a -> Partial a -> Bool
compare :: Partial a -> Partial a -> Ordering
$ccompare :: forall a. Ord a => Partial a -> Partial a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Partial a)
Ord, ReadPrec [Partial a]
ReadPrec (Partial a)
Int -> ReadS (Partial a)
ReadS [Partial a]
(Int -> ReadS (Partial a))
-> ReadS [Partial a]
-> ReadPrec (Partial a)
-> ReadPrec [Partial a]
-> Read (Partial a)
forall a. Read a => ReadPrec [Partial a]
forall a. Read a => ReadPrec (Partial a)
forall a. Read a => Int -> ReadS (Partial a)
forall a. Read a => ReadS [Partial a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Partial a]
$creadListPrec :: forall a. Read a => ReadPrec [Partial a]
readPrec :: ReadPrec (Partial a)
$creadPrec :: forall a. Read a => ReadPrec (Partial a)
readList :: ReadS [Partial a]
$creadList :: forall a. Read a => ReadS [Partial a]
readsPrec :: Int -> ReadS (Partial a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Partial a)
Read, Int -> Partial a -> ShowS
[Partial a] -> ShowS
Partial a -> String
(Int -> Partial a -> ShowS)
-> (Partial a -> String)
-> ([Partial a] -> ShowS)
-> Show (Partial a)
forall a. Show a => Int -> Partial a -> ShowS
forall a. Show a => [Partial a] -> ShowS
forall a. Show a => Partial a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Partial a] -> ShowS
$cshowList :: forall a. Show a => [Partial a] -> ShowS
show :: Partial a -> String
$cshow :: forall a. Show a => Partial a -> String
showsPrec :: Int -> Partial a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Partial a -> ShowS
Show)
instance PartialSemigroup a => Semigroup (Partial a)
where
Partial (Just a
x) <> :: Partial a -> Partial a -> Partial a
<> Partial (Just a
y) = Maybe a -> Partial a
forall a. Maybe a -> Partial a
Partial (a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y)
Partial a
_ <> Partial a
_ = Maybe a -> Partial a
forall a. Maybe a -> Partial a
Partial Maybe a
forall a. Maybe a
Nothing
newtype Total a = Total { Total a -> a
unTotal :: a }
deriving (Total a -> Total a -> Bool
(Total a -> Total a -> Bool)
-> (Total a -> Total a -> Bool) -> Eq (Total a)
forall a. Eq a => Total a -> Total a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Total a -> Total a -> Bool
$c/= :: forall a. Eq a => Total a -> Total a -> Bool
== :: Total a -> Total a -> Bool
$c== :: forall a. Eq a => Total a -> Total a -> Bool
Eq, Eq (Total a)
Eq (Total a)
-> (Total a -> Total a -> Ordering)
-> (Total a -> Total a -> Bool)
-> (Total a -> Total a -> Bool)
-> (Total a -> Total a -> Bool)
-> (Total a -> Total a -> Bool)
-> (Total a -> Total a -> Total a)
-> (Total a -> Total a -> Total a)
-> Ord (Total a)
Total a -> Total a -> Bool
Total a -> Total a -> Ordering
Total a -> Total a -> Total 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 (Total a)
forall a. Ord a => Total a -> Total a -> Bool
forall a. Ord a => Total a -> Total a -> Ordering
forall a. Ord a => Total a -> Total a -> Total a
min :: Total a -> Total a -> Total a
$cmin :: forall a. Ord a => Total a -> Total a -> Total a
max :: Total a -> Total a -> Total a
$cmax :: forall a. Ord a => Total a -> Total a -> Total a
>= :: Total a -> Total a -> Bool
$c>= :: forall a. Ord a => Total a -> Total a -> Bool
> :: Total a -> Total a -> Bool
$c> :: forall a. Ord a => Total a -> Total a -> Bool
<= :: Total a -> Total a -> Bool
$c<= :: forall a. Ord a => Total a -> Total a -> Bool
< :: Total a -> Total a -> Bool
$c< :: forall a. Ord a => Total a -> Total a -> Bool
compare :: Total a -> Total a -> Ordering
$ccompare :: forall a. Ord a => Total a -> Total a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Total a)
Ord, ReadPrec [Total a]
ReadPrec (Total a)
Int -> ReadS (Total a)
ReadS [Total a]
(Int -> ReadS (Total a))
-> ReadS [Total a]
-> ReadPrec (Total a)
-> ReadPrec [Total a]
-> Read (Total a)
forall a. Read a => ReadPrec [Total a]
forall a. Read a => ReadPrec (Total a)
forall a. Read a => Int -> ReadS (Total a)
forall a. Read a => ReadS [Total a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Total a]
$creadListPrec :: forall a. Read a => ReadPrec [Total a]
readPrec :: ReadPrec (Total a)
$creadPrec :: forall a. Read a => ReadPrec (Total a)
readList :: ReadS [Total a]
$creadList :: forall a. Read a => ReadS [Total a]
readsPrec :: Int -> ReadS (Total a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Total a)
Read, Int -> Total a -> ShowS
[Total a] -> ShowS
Total a -> String
(Int -> Total a -> ShowS)
-> (Total a -> String) -> ([Total a] -> ShowS) -> Show (Total a)
forall a. Show a => Int -> Total a -> ShowS
forall a. Show a => [Total a] -> ShowS
forall a. Show a => Total a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Total a] -> ShowS
$cshowList :: forall a. Show a => [Total a] -> ShowS
show :: Total a -> String
$cshow :: forall a. Show a => Total a -> String
showsPrec :: Int -> Total a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Total a -> ShowS
Show)
instance Semigroup a => PartialSemigroup (Total a)
where
Total a
x <>? :: Total a -> Total a -> Maybe (Total a)
<>? Total a
y = Total a -> Maybe (Total a)
forall a. a -> Maybe a
Just (a -> Total a
forall a. a -> Total a
Total (a
x a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
y))
newtype AppendLeft a b = AppendLeft { AppendLeft a b -> Either a b
unAppendLeft :: Either a b }
deriving (AppendLeft a b -> AppendLeft a b -> Bool
(AppendLeft a b -> AppendLeft a b -> Bool)
-> (AppendLeft a b -> AppendLeft a b -> Bool)
-> Eq (AppendLeft a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq a, Eq b) =>
AppendLeft a b -> AppendLeft a b -> Bool
/= :: AppendLeft a b -> AppendLeft a b -> Bool
$c/= :: forall a b.
(Eq a, Eq b) =>
AppendLeft a b -> AppendLeft a b -> Bool
== :: AppendLeft a b -> AppendLeft a b -> Bool
$c== :: forall a b.
(Eq a, Eq b) =>
AppendLeft a b -> AppendLeft a b -> Bool
Eq, Eq (AppendLeft a b)
Eq (AppendLeft a b)
-> (AppendLeft a b -> AppendLeft a b -> Ordering)
-> (AppendLeft a b -> AppendLeft a b -> Bool)
-> (AppendLeft a b -> AppendLeft a b -> Bool)
-> (AppendLeft a b -> AppendLeft a b -> Bool)
-> (AppendLeft a b -> AppendLeft a b -> Bool)
-> (AppendLeft a b -> AppendLeft a b -> AppendLeft a b)
-> (AppendLeft a b -> AppendLeft a b -> AppendLeft a b)
-> Ord (AppendLeft a b)
AppendLeft a b -> AppendLeft a b -> Bool
AppendLeft a b -> AppendLeft a b -> Ordering
AppendLeft a b -> AppendLeft a b -> AppendLeft a b
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 b. (Ord a, Ord b) => Eq (AppendLeft a b)
forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Bool
forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Ordering
forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> AppendLeft a b
min :: AppendLeft a b -> AppendLeft a b -> AppendLeft a b
$cmin :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> AppendLeft a b
max :: AppendLeft a b -> AppendLeft a b -> AppendLeft a b
$cmax :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> AppendLeft a b
>= :: AppendLeft a b -> AppendLeft a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Bool
> :: AppendLeft a b -> AppendLeft a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Bool
<= :: AppendLeft a b -> AppendLeft a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Bool
< :: AppendLeft a b -> AppendLeft a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Bool
compare :: AppendLeft a b -> AppendLeft a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
AppendLeft a b -> AppendLeft a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (AppendLeft a b)
Ord, ReadPrec [AppendLeft a b]
ReadPrec (AppendLeft a b)
Int -> ReadS (AppendLeft a b)
ReadS [AppendLeft a b]
(Int -> ReadS (AppendLeft a b))
-> ReadS [AppendLeft a b]
-> ReadPrec (AppendLeft a b)
-> ReadPrec [AppendLeft a b]
-> Read (AppendLeft a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [AppendLeft a b]
forall a b. (Read a, Read b) => ReadPrec (AppendLeft a b)
forall a b. (Read a, Read b) => Int -> ReadS (AppendLeft a b)
forall a b. (Read a, Read b) => ReadS [AppendLeft a b]
readListPrec :: ReadPrec [AppendLeft a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [AppendLeft a b]
readPrec :: ReadPrec (AppendLeft a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (AppendLeft a b)
readList :: ReadS [AppendLeft a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [AppendLeft a b]
readsPrec :: Int -> ReadS (AppendLeft a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (AppendLeft a b)
Read, Int -> AppendLeft a b -> ShowS
[AppendLeft a b] -> ShowS
AppendLeft a b -> String
(Int -> AppendLeft a b -> ShowS)
-> (AppendLeft a b -> String)
-> ([AppendLeft a b] -> ShowS)
-> Show (AppendLeft a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> AppendLeft a b -> ShowS
forall a b. (Show a, Show b) => [AppendLeft a b] -> ShowS
forall a b. (Show a, Show b) => AppendLeft a b -> String
showList :: [AppendLeft a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [AppendLeft a b] -> ShowS
show :: AppendLeft a b -> String
$cshow :: forall a b. (Show a, Show b) => AppendLeft a b -> String
showsPrec :: Int -> AppendLeft a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> AppendLeft a b -> ShowS
Show)
instance PartialSemigroup a => PartialSemigroup (AppendLeft a b)
where
AppendLeft (Left a
x) <>? :: AppendLeft a b -> AppendLeft a b -> Maybe (AppendLeft a b)
<>? AppendLeft (Left a
y) =
Either a b -> AppendLeft a b
forall a b. Either a b -> AppendLeft a b
AppendLeft (Either a b -> AppendLeft a b)
-> (a -> Either a b) -> a -> AppendLeft a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either a b
forall a b. a -> Either a b
Left (a -> AppendLeft a b) -> Maybe a -> Maybe (AppendLeft a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a
x a -> a -> Maybe a
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? a
y)
AppendLeft a b
_ <>? AppendLeft a b
_ = Maybe (AppendLeft a b)
forall a. Maybe a
Nothing
newtype AppendRight a b = AppendRight { AppendRight a b -> Either a b
unAppendRight :: Either a b }
deriving (AppendRight a b -> AppendRight a b -> Bool
(AppendRight a b -> AppendRight a b -> Bool)
-> (AppendRight a b -> AppendRight a b -> Bool)
-> Eq (AppendRight a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq a, Eq b) =>
AppendRight a b -> AppendRight a b -> Bool
/= :: AppendRight a b -> AppendRight a b -> Bool
$c/= :: forall a b.
(Eq a, Eq b) =>
AppendRight a b -> AppendRight a b -> Bool
== :: AppendRight a b -> AppendRight a b -> Bool
$c== :: forall a b.
(Eq a, Eq b) =>
AppendRight a b -> AppendRight a b -> Bool
Eq, Eq (AppendRight a b)
Eq (AppendRight a b)
-> (AppendRight a b -> AppendRight a b -> Ordering)
-> (AppendRight a b -> AppendRight a b -> Bool)
-> (AppendRight a b -> AppendRight a b -> Bool)
-> (AppendRight a b -> AppendRight a b -> Bool)
-> (AppendRight a b -> AppendRight a b -> Bool)
-> (AppendRight a b -> AppendRight a b -> AppendRight a b)
-> (AppendRight a b -> AppendRight a b -> AppendRight a b)
-> Ord (AppendRight a b)
AppendRight a b -> AppendRight a b -> Bool
AppendRight a b -> AppendRight a b -> Ordering
AppendRight a b -> AppendRight a b -> AppendRight a b
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 b. (Ord a, Ord b) => Eq (AppendRight a b)
forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Bool
forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Ordering
forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> AppendRight a b
min :: AppendRight a b -> AppendRight a b -> AppendRight a b
$cmin :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> AppendRight a b
max :: AppendRight a b -> AppendRight a b -> AppendRight a b
$cmax :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> AppendRight a b
>= :: AppendRight a b -> AppendRight a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Bool
> :: AppendRight a b -> AppendRight a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Bool
<= :: AppendRight a b -> AppendRight a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Bool
< :: AppendRight a b -> AppendRight a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Bool
compare :: AppendRight a b -> AppendRight a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
AppendRight a b -> AppendRight a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (AppendRight a b)
Ord, ReadPrec [AppendRight a b]
ReadPrec (AppendRight a b)
Int -> ReadS (AppendRight a b)
ReadS [AppendRight a b]
(Int -> ReadS (AppendRight a b))
-> ReadS [AppendRight a b]
-> ReadPrec (AppendRight a b)
-> ReadPrec [AppendRight a b]
-> Read (AppendRight a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [AppendRight a b]
forall a b. (Read a, Read b) => ReadPrec (AppendRight a b)
forall a b. (Read a, Read b) => Int -> ReadS (AppendRight a b)
forall a b. (Read a, Read b) => ReadS [AppendRight a b]
readListPrec :: ReadPrec [AppendRight a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [AppendRight a b]
readPrec :: ReadPrec (AppendRight a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (AppendRight a b)
readList :: ReadS [AppendRight a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [AppendRight a b]
readsPrec :: Int -> ReadS (AppendRight a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (AppendRight a b)
Read, Int -> AppendRight a b -> ShowS
[AppendRight a b] -> ShowS
AppendRight a b -> String
(Int -> AppendRight a b -> ShowS)
-> (AppendRight a b -> String)
-> ([AppendRight a b] -> ShowS)
-> Show (AppendRight a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> AppendRight a b -> ShowS
forall a b. (Show a, Show b) => [AppendRight a b] -> ShowS
forall a b. (Show a, Show b) => AppendRight a b -> String
showList :: [AppendRight a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [AppendRight a b] -> ShowS
show :: AppendRight a b -> String
$cshow :: forall a b. (Show a, Show b) => AppendRight a b -> String
showsPrec :: Int -> AppendRight a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> AppendRight a b -> ShowS
Show)
instance PartialSemigroup b => PartialSemigroup (AppendRight a b)
where
AppendRight (Right b
x) <>? :: AppendRight a b -> AppendRight a b -> Maybe (AppendRight a b)
<>? AppendRight (Right b
y) =
Either a b -> AppendRight a b
forall a b. Either a b -> AppendRight a b
AppendRight (Either a b -> AppendRight a b)
-> (b -> Either a b) -> b -> AppendRight a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either a b
forall a b. b -> Either a b
Right (b -> AppendRight a b) -> Maybe b -> Maybe (AppendRight a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (b
x b -> b -> Maybe b
forall a. PartialSemigroup a => a -> a -> Maybe a
<>? b
y)
AppendRight a b
_ <>? AppendRight a b
_ = Maybe (AppendRight a b)
forall a. Maybe a
Nothing
newtype One a = One { One a -> a
theOne :: a }
deriving (One a -> One a -> Bool
(One a -> One a -> Bool) -> (One a -> One a -> Bool) -> Eq (One a)
forall a. Eq a => One a -> One a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: One a -> One a -> Bool
$c/= :: forall a. Eq a => One a -> One a -> Bool
== :: One a -> One a -> Bool
$c== :: forall a. Eq a => One a -> One a -> Bool
Eq, Eq (One a)
Eq (One a)
-> (One a -> One a -> Ordering)
-> (One a -> One a -> Bool)
-> (One a -> One a -> Bool)
-> (One a -> One a -> Bool)
-> (One a -> One a -> Bool)
-> (One a -> One a -> One a)
-> (One a -> One a -> One a)
-> Ord (One a)
One a -> One a -> Bool
One a -> One a -> Ordering
One a -> One a -> One 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 (One a)
forall a. Ord a => One a -> One a -> Bool
forall a. Ord a => One a -> One a -> Ordering
forall a. Ord a => One a -> One a -> One a
min :: One a -> One a -> One a
$cmin :: forall a. Ord a => One a -> One a -> One a
max :: One a -> One a -> One a
$cmax :: forall a. Ord a => One a -> One a -> One a
>= :: One a -> One a -> Bool
$c>= :: forall a. Ord a => One a -> One a -> Bool
> :: One a -> One a -> Bool
$c> :: forall a. Ord a => One a -> One a -> Bool
<= :: One a -> One a -> Bool
$c<= :: forall a. Ord a => One a -> One a -> Bool
< :: One a -> One a -> Bool
$c< :: forall a. Ord a => One a -> One a -> Bool
compare :: One a -> One a -> Ordering
$ccompare :: forall a. Ord a => One a -> One a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (One a)
Ord, ReadPrec [One a]
ReadPrec (One a)
Int -> ReadS (One a)
ReadS [One a]
(Int -> ReadS (One a))
-> ReadS [One a]
-> ReadPrec (One a)
-> ReadPrec [One a]
-> Read (One a)
forall a. Read a => ReadPrec [One a]
forall a. Read a => ReadPrec (One a)
forall a. Read a => Int -> ReadS (One a)
forall a. Read a => ReadS [One a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [One a]
$creadListPrec :: forall a. Read a => ReadPrec [One a]
readPrec :: ReadPrec (One a)
$creadPrec :: forall a. Read a => ReadPrec (One a)
readList :: ReadS [One a]
$creadList :: forall a. Read a => ReadS [One a]
readsPrec :: Int -> ReadS (One a)
$creadsPrec :: forall a. Read a => Int -> ReadS (One a)
Read, Int -> One a -> ShowS
[One a] -> ShowS
One a -> String
(Int -> One a -> ShowS)
-> (One a -> String) -> ([One a] -> ShowS) -> Show (One a)
forall a. Show a => Int -> One a -> ShowS
forall a. Show a => [One a] -> ShowS
forall a. Show a => One a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [One a] -> ShowS
$cshowList :: forall a. Show a => [One a] -> ShowS
show :: One a -> String
$cshow :: forall a. Show a => One a -> String
showsPrec :: Int -> One a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> One a -> ShowS
Show)
instance PartialSemigroup (One a)
where
One a
_ <>? :: One a -> One a -> Maybe (One a)
<>? One a
_ = Maybe (One a)
forall a. Maybe a
Nothing
newtype AtMostOne a = AtMostOne { AtMostOne a -> Maybe a
theOneMaybe :: Maybe a }
deriving (AtMostOne a -> AtMostOne a -> Bool
(AtMostOne a -> AtMostOne a -> Bool)
-> (AtMostOne a -> AtMostOne a -> Bool) -> Eq (AtMostOne a)
forall a. Eq a => AtMostOne a -> AtMostOne a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AtMostOne a -> AtMostOne a -> Bool
$c/= :: forall a. Eq a => AtMostOne a -> AtMostOne a -> Bool
== :: AtMostOne a -> AtMostOne a -> Bool
$c== :: forall a. Eq a => AtMostOne a -> AtMostOne a -> Bool
Eq, Eq (AtMostOne a)
Eq (AtMostOne a)
-> (AtMostOne a -> AtMostOne a -> Ordering)
-> (AtMostOne a -> AtMostOne a -> Bool)
-> (AtMostOne a -> AtMostOne a -> Bool)
-> (AtMostOne a -> AtMostOne a -> Bool)
-> (AtMostOne a -> AtMostOne a -> Bool)
-> (AtMostOne a -> AtMostOne a -> AtMostOne a)
-> (AtMostOne a -> AtMostOne a -> AtMostOne a)
-> Ord (AtMostOne a)
AtMostOne a -> AtMostOne a -> Bool
AtMostOne a -> AtMostOne a -> Ordering
AtMostOne a -> AtMostOne a -> AtMostOne 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 (AtMostOne a)
forall a. Ord a => AtMostOne a -> AtMostOne a -> Bool
forall a. Ord a => AtMostOne a -> AtMostOne a -> Ordering
forall a. Ord a => AtMostOne a -> AtMostOne a -> AtMostOne a
min :: AtMostOne a -> AtMostOne a -> AtMostOne a
$cmin :: forall a. Ord a => AtMostOne a -> AtMostOne a -> AtMostOne a
max :: AtMostOne a -> AtMostOne a -> AtMostOne a
$cmax :: forall a. Ord a => AtMostOne a -> AtMostOne a -> AtMostOne a
>= :: AtMostOne a -> AtMostOne a -> Bool
$c>= :: forall a. Ord a => AtMostOne a -> AtMostOne a -> Bool
> :: AtMostOne a -> AtMostOne a -> Bool
$c> :: forall a. Ord a => AtMostOne a -> AtMostOne a -> Bool
<= :: AtMostOne a -> AtMostOne a -> Bool
$c<= :: forall a. Ord a => AtMostOne a -> AtMostOne a -> Bool
< :: AtMostOne a -> AtMostOne a -> Bool
$c< :: forall a. Ord a => AtMostOne a -> AtMostOne a -> Bool
compare :: AtMostOne a -> AtMostOne a -> Ordering
$ccompare :: forall a. Ord a => AtMostOne a -> AtMostOne a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (AtMostOne a)
Ord, ReadPrec [AtMostOne a]
ReadPrec (AtMostOne a)
Int -> ReadS (AtMostOne a)
ReadS [AtMostOne a]
(Int -> ReadS (AtMostOne a))
-> ReadS [AtMostOne a]
-> ReadPrec (AtMostOne a)
-> ReadPrec [AtMostOne a]
-> Read (AtMostOne a)
forall a. Read a => ReadPrec [AtMostOne a]
forall a. Read a => ReadPrec (AtMostOne a)
forall a. Read a => Int -> ReadS (AtMostOne a)
forall a. Read a => ReadS [AtMostOne a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AtMostOne a]
$creadListPrec :: forall a. Read a => ReadPrec [AtMostOne a]
readPrec :: ReadPrec (AtMostOne a)
$creadPrec :: forall a. Read a => ReadPrec (AtMostOne a)
readList :: ReadS [AtMostOne a]
$creadList :: forall a. Read a => ReadS [AtMostOne a]
readsPrec :: Int -> ReadS (AtMostOne a)
$creadsPrec :: forall a. Read a => Int -> ReadS (AtMostOne a)
Read, Int -> AtMostOne a -> ShowS
[AtMostOne a] -> ShowS
AtMostOne a -> String
(Int -> AtMostOne a -> ShowS)
-> (AtMostOne a -> String)
-> ([AtMostOne a] -> ShowS)
-> Show (AtMostOne a)
forall a. Show a => Int -> AtMostOne a -> ShowS
forall a. Show a => [AtMostOne a] -> ShowS
forall a. Show a => AtMostOne a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AtMostOne a] -> ShowS
$cshowList :: forall a. Show a => [AtMostOne a] -> ShowS
show :: AtMostOne a -> String
$cshow :: forall a. Show a => AtMostOne a -> String
showsPrec :: Int -> AtMostOne a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> AtMostOne a -> ShowS
Show)
instance PartialSemigroup (AtMostOne a)
where
AtMostOne Maybe a
Nothing <>? :: AtMostOne a -> AtMostOne a -> Maybe (AtMostOne a)
<>? AtMostOne a
x = AtMostOne a -> Maybe (AtMostOne a)
forall a. a -> Maybe a
Just AtMostOne a
x
AtMostOne a
x <>? AtMostOne Maybe a
Nothing = AtMostOne a -> Maybe (AtMostOne a)
forall a. a -> Maybe a
Just AtMostOne a
x
AtMostOne a
_ <>? AtMostOne a
_ = Maybe (AtMostOne a)
forall a. Maybe a
Nothing