predicate-typed-0.7.4.0: Predicates, Refinement types and Dsl

Safe HaskellNone
LanguageHaskell2010

Predicate.Data.Tuple

Contents

Description

promoted tuple functions

Synopsis

arrows

data Dup #

duplicate a value into a tuple

>>> pl @Dup 4
Present (4,4) ('(4,4))
Val (4,4)
>>> pl @(Dup >> Id) 4
Present (4,4) ((>>) (4,4) | {Id (4,4)})
Val (4,4)
>>> pl @(Dup << Fst * Snd) (4,5)
Present (20,20) ((>>) (20,20) | {'(20,20)})
Val (20,20)
>>> pl @(Fst * Snd >> Dup) (4,5)
Present (20,20) ((>>) (20,20) | {'(20,20)})
Val (20,20)
Instances
Show Dup # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> Dup -> ShowS #

show :: Dup -> String #

showList :: [Dup] -> ShowS #

Show x => P Dup x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP Dup x :: Type #

Methods

eval :: MonadEval m => proxy Dup -> POpts -> x -> m (TT (PP Dup x)) #

type PP Dup x # 
Instance details

Defined in Predicate.Data.Tuple

type PP Dup x

data First p #

applies a function against the first part of a tuple: similar to first

>>> pz @(First Succ) (12,True)
Val (13,True)
Instances
P (FirstT p) x => P (First p :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (First p) x :: Type #

Methods

eval :: MonadEval m => proxy (First p) -> POpts -> x -> m (TT (PP (First p) x)) #

Show (First p) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> First p -> ShowS #

show :: First p -> String #

showList :: [First p] -> ShowS #

type PP (First p :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (First p :: Type) x

data Second q #

applies a function against the second part of a tuple: similar to second

>>> pz @(Second Succ) (12,False)
Val (12,True)
Instances
P (SecondT q) x => P (Second q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (Second q) x :: Type #

Methods

eval :: MonadEval m => proxy (Second q) -> POpts -> x -> m (TT (PP (Second q) x)) #

Show (Second q) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> Second q -> ShowS #

show :: Second q -> String #

showList :: [Second q] -> ShowS #

type PP (Second q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (Second q :: Type) x

data p &&& q infixr 3 #

similar to &&&

>>> pl @(Min &&& Max >> Id >> Fst < Snd) [10,4,2,12,14]
True ((>>) True | {2 < 14})
Val True
>>> pl @((123 &&& Id) >> Fst + Snd) 4
Present 127 ((>>) 127 | {123 + 4 = 127})
Val 127
>>> pl @(4 &&& "sadf" &&& 'LT) ()
Present (4,("sadf",LT)) ('(4,("sadf",LT)))
Val (4,("sadf",LT))
>>> pl @(Id &&& '() &&& ()) (Just 10)
Present (Just 10,((),())) ('(Just 10,((),())))
Val (Just 10,((),()))
>>> pl @(Fst &&& Snd &&& Thd &&& ()) (1,'x',True)
Present (1,('x',(True,()))) ('(1,('x',(True,()))))
Val (1,('x',(True,())))
>>> pl @(Fst &&& Snd &&& Thd &&& ()) (1,'x',True)
Present (1,('x',(True,()))) ('(1,('x',(True,()))))
Val (1,('x',(True,())))
>>> pl @(Fst &&& Snd &&& Thd &&& ()) (1,1.4,"aaa")
Present (1,(1.4,("aaa",()))) ('(1,(1.4,("aaa",()))))
Val (1,(1.4,("aaa",())))
Instances
P (WAmpT p q) x => P (p &&& q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (p &&& q) x :: Type #

Methods

eval :: MonadEval m => proxy (p &&& q) -> POpts -> x -> m (TT (PP (p &&& q) x)) #

Show (p &&& q) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> (p &&& q) -> ShowS #

show :: (p &&& q) -> String #

showList :: [p &&& q] -> ShowS #

type PP (p &&& q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (p &&& q :: Type) x

data p *** q infixr 3 #

similar to ***

>>> pz @(Pred *** ShowP Id) (13, True)
Val (12,"True")
>>> pl @(FlipT (***) Len (Id * 12)) (99,"cdef")
Present (1188,4) ((***) (1188,4) | (99,"cdef"))
Val (1188,4)
>>> pl @(4 *** "sadf" *** 'LT) ('x',("abv",[1]))
Present (4,("sadf",LT)) ((***) (4,("sadf",LT)) | ('x',("abv",[1])))
Val (4,("sadf",LT))
Instances
(Show (PP p a), Show (PP q b), P p a, P q b, Show a, Show b) => P (p *** q :: Type) (a, b) # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (p *** q) (a, b) :: Type #

Methods

eval :: MonadEval m => proxy (p *** q) -> POpts -> (a, b) -> m (TT (PP (p *** q) (a, b))) #

Show (p *** q) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> (p *** q) -> ShowS #

show :: (p *** q) -> String #

showList :: [p *** q] -> ShowS #

type PP (p *** q :: Type) (a, b) # 
Instance details

Defined in Predicate.Data.Tuple

type PP (p *** q :: Type) (a, b) = (PP p a, PP q b)

data Both p #

applies p to the first and second slot of an n-tuple (similar to ***)

>>> pl @(Fst >> Both Len) (("abc",[10..17]),True)
Present (3,8) ((>>) (3,8) | {Both})
Val (3,8)
>>> pl @(Lift (Both Pred) Fst) ((12,'z'),True)
Present (11,'y') ((>>) (11,'y') | {Both})
Val (11,'y')
>>> pl @(Both Succ) (4,'a')
Present (5,'b') (Both)
Val (5,'b')
>>> import Data.Time
>>> pl @(Both (ReadP Day Id)) ("1999-01-01","2001-02-12")
Present (1999-01-01,2001-02-12) (Both)
Val (1999-01-01,2001-02-12)
Instances
(P p a, P p a') => P (Both p :: Type) (a, a') # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (Both p) (a, a') :: Type #

Methods

eval :: MonadEval m => proxy (Both p) -> POpts -> (a, a') -> m (TT (PP (Both p) (a, a'))) #

Show (Both p) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> Both p -> ShowS #

show :: Both p -> String #

showList :: [Both p] -> ShowS #

type PP (Both p :: Type) (a, a') # 
Instance details

Defined in Predicate.Data.Tuple

type PP (Both p :: Type) (a, a') = (PP p a, PP p a')

data On (p :: Type -> Type -> k2) q #

similar to on

>>> pz @('(4,2) >> On (**) (FromIntegral _)) ()
Val 16.0
>>> pz @(On (+) (Id * Id) >> Id ** (1 % 2 >> FromRational _)) (3,4)
Val 5.0
Instances
(P q a, P q a', P (p Fst Snd) (PP q a, PP q a')) => P (On p q :: Type) (a, a') # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (On p q) (a, a') :: Type #

Methods

eval :: MonadEval m => proxy (On p q) -> POpts -> (a, a') -> m (TT (PP (On p q) (a, a'))) #

Show (On p q) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> On p q -> ShowS #

show :: On p q -> String #

showList :: [On p q] -> ShowS #

type PP (On p q :: Type) (a, a') # 
Instance details

Defined in Predicate.Data.Tuple

type PP (On p q :: Type) (a, a') = PP (p Fst Snd) (PP q a, PP q a')

flat tuples

data Tuple (n :: Nat) #

create a n tuple from a list

>>> pz @(Tuple 4) "abcdefg"
Val ('a','b','c','d')
>>> pz @(Tuple 4) "abc"
Fail "Tuple(4) not enough elements(3)"
>>> pz @(Fst >> Tuple 3) ([1..5],True)
Val (1,2,3)
>>> pz @(Lift (Tuple 3) Fst) ([1..5],True)
Val (1,2,3)
Instances
Show (Tuple n) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> Tuple n -> ShowS #

show :: Tuple n -> String #

showList :: [Tuple n] -> ShowS #

(KnownNat n, FailWhenT (n <=? 1) (Text "Tuple:n cannot be less than two but found n=" :<>: ShowType n), TupleC n a, x ~ [a], Show a) => P (Tuple n :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (Tuple n) x :: Type #

Methods

eval :: MonadEval m => proxy (Tuple n) -> POpts -> x -> m (TT (PP (Tuple n) x)) #

type PP (Tuple n :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (Tuple n :: Type) x = TupleT n (ExtractAFromList x)

data Tuple' (n :: Nat) #

create a n tuple from a list

>>> pz @(Tuple' 4) "abcdefg"
Val (Right ('a','b','c','d'))
>>> pz @(Tuple' 4) "abc"
Val (Left "abc")
>>> pz @(Tuple' 4) []
Val (Left [])
>>> pl @(Tuple' 4) "abc"
Present Left "abc" (Tuple'(4) not enough elements(3))
Val (Left "abc")
>>> :set -XPolyKinds
>>> type F n i = ChunksOf' n i Id >> Map (Tuple' n) >> PartitionEithers
>>> pz @(F 3 1) [1..7]
Val ([[6,7],[7]],[(1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,6,7)])
Instances
Show (Tuple' n) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> Tuple' n -> ShowS #

show :: Tuple' n -> String #

showList :: [Tuple' n] -> ShowS #

(KnownNat n, FailWhenT (n <=? 1) (Text "Tuple':n cannot be less than two but found n=" :<>: ShowType n), TupleC n a, x ~ [a]) => P (Tuple' n :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (Tuple' n) x :: Type #

Methods

eval :: MonadEval m => proxy (Tuple' n) -> POpts -> x -> m (TT (PP (Tuple' n) x)) #

type PP (Tuple' n :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (Tuple' n :: Type) x = Either x (TupleT n (ExtractAFromList x))

data Pairs #

creates a list of overlapping pairs of elements. requires two or more elements

>>> pz @Pairs [1,2,3,4]
Val [(1,2),(2,3),(3,4)]
>>> pz @Pairs []
Val []
>>> pz @Pairs [1]
Val []
>>> pl @Pairs [1,2]
Present [(1,2)] (Pairs [(1,2)] | [1,2])
Val [(1,2)]
>>> pl @Pairs [1,2,3]
Present [(1,2),(2,3)] (Pairs [(1,2),(2,3)] | [1,2,3])
Val [(1,2),(2,3)]
>>> pl @Pairs [1,2,3,4]
Present [(1,2),(2,3),(3,4)] (Pairs [(1,2),(2,3),(3,4)] | [1,2,3,4])
Val [(1,2),(2,3),(3,4)]
>>> pan @(Pairs >> Len >> 'True >> 'False >> FailT _ "xyzzy") "abcde"
[Error xyzzy] False
|
+- P Pairs [('a','b'),('b','c'),('c','d'),('d','e')]
|
+- P Len 4
|
+- True 'True
|
+- False 'False
|
`- [Error xyzzy]
Fail "xyzzy"
Instances
Show Pairs # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> Pairs -> ShowS #

show :: Pairs -> String #

showList :: [Pairs] -> ShowS #

([a] ~ x, Show a) => P Pairs x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP Pairs x :: Type #

Methods

eval :: MonadEval m => proxy Pairs -> POpts -> x -> m (TT (PP Pairs x)) #

type PP Pairs x # 
Instance details

Defined in Predicate.Data.Tuple

boolean

data AndA p q r #

applies p to lhs of the tuple and q to the rhs and then ands them together: see &*

>>> pl @(AndA (Gt 3) (Lt 10) Id) (1,2)
False (False (&*) True | (1 > 3))
Val False
Instances
(PP r x ~ (a, b), PP p a ~ Bool, PP q b ~ Bool, P p a, P q b, P r x) => P (AndA p q r :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (AndA p q r) x :: Type #

Methods

eval :: MonadEval m => proxy (AndA p q r) -> POpts -> x -> m (TT (PP (AndA p q r) x)) #

Show (AndA p q r) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> AndA p q r -> ShowS #

show :: AndA p q r -> String #

showList :: [AndA p q r] -> ShowS #

type PP (AndA p q r :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (AndA p q r :: Type) x = Bool

data p &* q infixr 3 #

applies p to lhs of the tuple and q to the rhs and then Ands them together

>>> pl @(SplitAt 4 "abcdefg" >> Len > 4 &* Len < 5) ()
False ((>>) False | {False (&*) True | (4 > 4)})
Val False
Instances
P (AndAT p q) x => P (p &* q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (p &* q) x :: Type #

Methods

eval :: MonadEval m => proxy (p &* q) -> POpts -> x -> m (TT (PP (p &* q) x)) #

Show (p &* q) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> (p &* q) -> ShowS #

show :: (p &* q) -> String #

showList :: [p &* q] -> ShowS #

type PP (p &* q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (p &* q :: Type) x

data OrA p q r #

applies p to lhs of the tuple and q to the rhs and then ors them together: see |+

>>> pl @(OrA (Gt 3) (Lt 10) Id) (1,2)
True (False (|+) True)
Val True
Instances
(PP r x ~ (a, b), PP p a ~ Bool, PP q b ~ Bool, P p a, P q b, P r x) => P (OrA p q r :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (OrA p q r) x :: Type #

Methods

eval :: MonadEval m => proxy (OrA p q r) -> POpts -> x -> m (TT (PP (OrA p q r) x)) #

Show (OrA p q r) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> OrA p q r -> ShowS #

show :: OrA p q r -> String #

showList :: [OrA p q r] -> ShowS #

type PP (OrA p q r :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (OrA p q r :: Type) x = Bool

data p |+ q infixr 3 #

applies p to lhs of the tuple and q to the rhs and then Ors them together

>>> pl @(Sum > 44 |+ Id < 2) ([5,6,7,8,14,44],9)
True (True (|+) False)
Val True
>>> pl @(Sum > 44 |+ Id < 2) ([5,6,7,14],9)
False (False (|+) False | (32 > 44) (|+) (9 < 2))
Val False
>>> pl @(Sum > 44 |+ Id < 2) ([5,6,7,14],1)
True (False (|+) True)
Val True
Instances
P (OrAT p q) x => P (p |+ q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (p |+ q) x :: Type #

Methods

eval :: MonadEval m => proxy (p |+ q) -> POpts -> x -> m (TT (PP (p |+ q) x)) #

Show (p |+ q) # 
Instance details

Defined in Predicate.Data.Tuple

Methods

showsPrec :: Int -> (p |+ q) -> ShowS #

show :: (p |+ q) -> String #

showList :: [p |+ q] -> ShowS #

type PP (p |+ q :: Type) x # 
Instance details

Defined in Predicate.Data.Tuple

type PP (p |+ q :: Type) x

inductive tuples

data EachITuple p #

run p with inductive tuples

>>> pz @(EachITuple Succ) (False,(2,(LT,('c',()))))
Val (True,(3,(EQ,('d',()))))
>>> pz @(EachITuple (Id + (4 >> FromIntegral _))) (1,(1/4,(5%6,())))
Val (5 % 1,(17 % 4,(29 % 6,())))
>>> pz @(ToITuple >> EachITuple (Id + (4 >> FromIntegral _))) (1000,1/4,5%6)
Val (1004 % 1,(17 % 4,(29 % 6,())))
>>> pz @(ToITuple >> EachITuple ((Id >> FromIntegral _) + (4 >> FromIntegral _))) (1000::Integer,17::Int)
Val (1004,(21,()))
>>> pz @(ToITuple >> EachITuple (Dup >> Fst<>Snd)) (SG.Min 1,SG.First 'x',"abcd")
Val (Min {getMin = 1},(First {getFirst = 'x'},("abcdabcd",())))
Instances
P (EachITuple p :: Type) () # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (EachITuple p) () :: Type #

Methods

eval :: MonadEval m => proxy (EachITuple p) -> POpts -> () -> m (TT (PP (EachITuple p) ())) #

(P p b, P (EachITuple p) bs) => P (EachITuple p :: Type) (b, bs) # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (EachITuple p) (b, bs) :: Type #

Methods

eval :: MonadEval m => proxy (EachITuple p) -> POpts -> (b, bs) -> m (TT (PP (EachITuple p) (b, bs))) #

Show (EachITuple p) # 
Instance details

Defined in Predicate.Data.Tuple

type PP (EachITuple p :: Type) () # 
Instance details

Defined in Predicate.Data.Tuple

type PP (EachITuple p :: Type) () = ()
type PP (EachITuple p :: Type) (b, bs) # 
Instance details

Defined in Predicate.Data.Tuple

type PP (EachITuple p :: Type) (b, bs) = (PP p b, PP (EachITuple p) bs)

data ToITuple #

create inductive tuples from flat tuples

>>> pz @(ToITuple >> EachITuple Succ) (1,2,False,'x')
Val (2,(3,(True,('y',()))))
Instances
Show ToITuple # 
Instance details

Defined in Predicate.Data.Tuple

ToITupleC x => P ToITuple x # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP ToITuple x :: Type #

Methods

eval :: MonadEval m => proxy ToITuple -> POpts -> x -> m (TT (PP ToITuple x)) #

type PP ToITuple x # 
Instance details

Defined in Predicate.Data.Tuple

type PP ToITuple x = ToITupleP x

data ReverseITuple #

reverse an inductive tuple

>>> pz @ReverseITuple (1.4,(1,(2,(False,('x',())))))
Val ('x',(False,(2,(1,(1.4,())))))
Instances
Show ReverseITuple # 
Instance details

Defined in Predicate.Data.Tuple

P ReverseITuple () # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP ReverseITuple () :: Type #

Methods

eval :: MonadEval m => proxy ReverseITuple -> POpts -> () -> m (TT (PP ReverseITuple ())) #

ReverseITupleC x xs () => P ReverseITuple (x, xs) # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP ReverseITuple (x, xs) :: Type #

Methods

eval :: MonadEval m => proxy ReverseITuple -> POpts -> (x, xs) -> m (TT (PP ReverseITuple (x, xs))) #

type PP ReverseITuple () # 
Instance details

Defined in Predicate.Data.Tuple

type PP ReverseITuple () = ()
type PP ReverseITuple (x, xs) # 
Instance details

Defined in Predicate.Data.Tuple

type PP ReverseITuple (x, xs) = ReverseITupleT x xs ()

data ToITupleList (n :: Nat) #

create inductive tuples from a list of the exact size n

>>> pz @(ToITupleList 4 >> EachITuple Succ) ['a','c','y','B']
Val ('b',('d',('z',('C',()))))
>>> pz @(ToITupleList 4) ['a','c','y','B']
Val ('a',('c',('y',('B',()))))
>>> pz @(Take 10 Id >> ToITupleList 10) ['a'..'z']
Val ('a',('b',('c',('d',('e',('f',('g',('h',('i',('j',()))))))))))
Instances
Show (ToITupleList n) # 
Instance details

Defined in Predicate.Data.Tuple

(KnownNat n, FailWhenT (n <=? 0) (Text "ToITupleList:n cannot be 0"), ToITupleListC n a, xs ~ [a]) => P (ToITupleList n :: Type) xs # 
Instance details

Defined in Predicate.Data.Tuple

Associated Types

type PP (ToITupleList n) xs :: Type #

Methods

eval :: MonadEval m => proxy (ToITupleList n) -> POpts -> xs -> m (TT (PP (ToITupleList n) xs)) #

type PP (ToITupleList n :: Type) xs # 
Instance details

Defined in Predicate.Data.Tuple