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

Predicate.Data.Condition

Contents

Description

promoted conditional functions

Synopsis

## functions

data If p q r Source #

similar to an if statement: if p then run q else run r

>>> pz @(If (Gt 4) "greater than 4" "less than or equal to 4") 10
Val "greater than 4"
>>> pz @(If (Gt 4) "greater than 4" "less than or equal to 4") 0
Val "less than or equal to 4"
>>> pz @(If (Snd == "a") '("xxx",Fst + 13) (If (Snd == "b") '("yyy",Fst + 7) (FailT _ "oops"))) (99,"b")
Val ("yyy",106)
>>> pl @(If (Len > 2) (Map Succ) (FailS "someval")) [12,15,16]
Present [13,16,17] (If 'True [13,16,17])
Val [13,16,17]
>>> pl @(Map (If (Lt 3) 'True (FailT _ "err"))) [1..10]
Error err(8) (Map(i=2, a=3) excnt=8)
Fail "err(8)"
>>> pl @(Map (If (Lt 3) 'True (FailT _ "someval"))) [1..10]
Error someval(8) (Map(i=2, a=3) excnt=8)
Fail "someval(8)"
>>> pl @(Map (If (Lt 3) 'True 'False)) [1..5]
Present [True,True,False,False,False] (Map [True,True,False,False,False] | [1,2,3,4,5])
Val [True,True,False,False,False]
>>> pl @(If (Gt 4) (Fail (Hole _) (PrintF "failing with %d" Id)) ()) 45
Error failing with 45 (If 'True)
Fail "failing with 45"
>>> pl @(If (Gt 4) (Fail (Hole _) (PrintF "failing with %d" Id)) (Id * 7)) 3
Present 21 (If 'False 21)
Val 21
>>> pl @(If (Gt 4) (FailT _ (PrintF "failing with %d" Id)) (Id * 7 >> ShowP Id >> Ones)) 3
Present ["2","1"] (If 'False ["2","1"])
Val ["2","1"]
>>> pl @(If (Gt 4) (FailT _ (PrintF "failing with %d" Id)) (ShowP (Id * 7) >> Ones)) 19
Error failing with 19 (If 'True)
Fail "failing with 19"

#### Instances

Instances details
 (Show (PP r a), P p a, PP p a ~ Bool, P q a, P r a, PP q a ~ PP r a) => P (If p q r :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (If p q r) a Source # Methodseval :: MonadEval m => proxy (If p q r) -> POpts -> a -> m (TT (PP (If p q r) a)) Source # Show (If p q r) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> If p q r -> ShowS #show :: If p q r -> String #showList :: [If p q r] -> ShowS # type PP (If p q r :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition type PP (If p q r :: Type) a = PP q a

data Case (e :: k0) (ps :: [k]) (qs :: [k1]) (r :: k2) Source #

tries to match the value r with a condition in ps and if there is a match calls the associated qs entry else run e ps = conditions qs = what to do [one to one with ps] r = the value e = otherwise -- leave til later

>>> pl @(Case (Snd >> FailP "xx") '[Gt 3, Lt 2, Same 3] '["gt3","lt2","eq3"] Id) 15
Present "gt3" (Case(0 of 2) "gt3" | 15)
Val "gt3"
>>> pl @(Case (Snd >> FailP "xx") '[Gt 3, Lt 2, Same 3] '["gt3","lt2","eq3"] Id) 1
Present "lt2" (Case(0) "lt2" | 1)
Val "lt2"
>>> pl @(Case (Snd >> FailP "xx") '[Gt 3, Lt 2, Same 3] '["gt3","lt2","eq3"] Id) 3
Present "eq3" (Case(0) "eq3" | 3)
Val "eq3"
>>> pl @(Case (Snd >> FailP "no match") '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 15
Error no match (Case:otherwise failed:Proxy)
Fail "no match"
>>> pl @(Case (Fail (Snd >> UnproxyT) (PrintF "no match for %03d" Fst)) '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 15
Error no match for 015 (Case:otherwise failed)
Fail "no match for 015"
>>> pl @(Case "other" '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 15
Present "other" (Case(0) "other" | 15)
Val "other"
>>> pl @(Case (ShowP Fst >> Id <> Id <> Id) '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 15
Present "151515" (Case(0) "151515" | 15)
Val "151515"
>>> pz @(Case (FailT _ "asdf") '[Lt 4,Lt 10,Same 50] '[PrintF "%d is lt4" Id, PrintF "%d is lt10" Id, PrintF "%d is same50" Id] Id) 50
Val "50 is same50"
>>> pz @(Case (FailT _ "asdf") '[Lt 4,Lt 10,Same 50] '[PrintF "%d is lt4" Id, PrintF "%d is lt10" Id, PrintF "%d is same50" Id] Id) 9
Val "9 is lt10"
>>> pz @(Case (FailT _ "asdf") '[Lt 4,Lt 10,Same 50] '[PrintF "%d is lt4" Id, PrintF "%d is lt10" Id, PrintF "%d is same50" Id] Id) 3
Val "3 is lt4"
>>> pz @(Case (FailT _ "asdf") '[Lt 4,Lt 10,Same 50] '[PrintF "%d is lt4" Id, PrintF "%d is lt10" Id, PrintF "%d is same50" Id] Id) 99
Fail "asdf"
>>> pz @(Case (FailS "asdf" >> Snd >> UnproxyT) '[Lt 4,Lt 10,Same 50] '[PrintF "%d is lt4" Id, PrintF "%d is lt10" Id, PrintF "%d is same50" Id] Id) 99
Fail "asdf"
>>> pz @(Case (FailT _ "x") '[Same "a",Same "b"] '["hey","there"] Id) "b"
Val "there"
>>> pz @(Case (FailT _ "x") '[Id == "a",Id == "b"] '["hey","there"] Id) "a"
Val "hey"
>>> pz @(Case (FailT _ "x") '[Same "a",Same "b"] '["hey","there"] Id) "c"
Fail "x"

#### Instances

Instances details
 (FailUnlessT (LenT ps == LenT qs) ((('Text "lengths are not the same " :<>: 'ShowType (LenT ps)) :<>: 'Text " vs ") :<>: 'ShowType (LenT qs)), P (CaseImplT e ps qs r) x) => P (Case e ps qs r :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (Case e ps qs r) x Source # Methodseval :: MonadEval m => proxy (Case e ps qs r) -> POpts -> x -> m (TT (PP (Case e ps qs r) x)) Source # Show (Case e ps qs r) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> Case e ps qs r -> ShowS #show :: Case e ps qs r -> String #showList :: [Case e ps qs r] -> ShowS # type PP (Case e ps qs r :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (Case e ps qs r :: Type) x

data Case' (ps :: [k]) (qs :: [k1]) (r :: k2) Source #

like Case but uses a generic error message (skips the e parameter)

>>> pl @(Case' '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 15
Error Case:no match (Case:otherwise failed:Proxy)
Fail "Case:no match"

#### Instances

Instances details
 P (CaseT' ps qs r) x => P (Case' ps qs r :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (Case' ps qs r) x Source # Methodseval :: MonadEval m => proxy (Case' ps qs r) -> POpts -> x -> m (TT (PP (Case' ps qs r) x)) Source # Show (Case' ps qs r) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> Case' ps qs r -> ShowS #show :: Case' ps qs r -> String #showList :: [Case' ps qs r] -> ShowS # type PP (Case' ps qs r :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (Case' ps qs r :: Type) x

data Case'' s (ps :: [k]) (qs :: [k1]) (r :: k2) Source #

like Case but allows you to use the value in the error message

>>> pl @(Case'' (PrintF "no match for %03d" Id) '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 15
Error no match for 015 (Case:otherwise failed)
Fail "no match for 015"
>>> pl @(Case'' (PrintF "no match for %03d" Id) '[Same 1, Same 2, Same 3] '["eq1","eq2","eq3"] Id) 2
Present "eq2" (Case(0) "eq2" | 2)
Val "eq2"
>>> pl @(Case'' (PrintF "no match for %04d" Id) '[Between 0 5 Id, Same 6, Between 7 10 Id] '[ 'LT, 'EQ, 'GT] Id) (-12)
Error no match for -012 (Case:otherwise failed)
Fail "no match for -012"

#### Instances

Instances details
 P (CaseT'' s ps qs r) x => P (Case'' s ps qs r :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (Case'' s ps qs r) x Source # Methodseval :: MonadEval m => proxy (Case'' s ps qs r) -> POpts -> x -> m (TT (PP (Case'' s ps qs r) x)) Source # Show (Case'' s ps qs r) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> Case'' s ps qs r -> ShowS #show :: Case'' s ps qs r -> String #showList :: [Case'' s ps qs r] -> ShowS # type PP (Case'' s ps qs r :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (Case'' s ps qs r :: Type) x

data Guards (ps :: [(k, k1)]) Source #

Guards contain a type level list of tuples the action to run on failure of the predicate and the predicate itself Each tuple validating against the corresponding value in a value list

prt receives (Int,a) as input which is the position and value if there is a failure

>>> pz @(Guards '[ '("arg1 failed",Gt 4), '("arg2 failed", Same 4)]) [17,4]
Val [17,4]
>>> pz @(Guards '[ '("arg1 failed",Gt 4), '("arg2 failed", Same 5)]) [17,4]
Fail "arg2 failed"
>>> pz @(Guards '[ '("arg1 failed",Gt 99), '("arg2 failed", Same 4)]) [17,4]
Fail "arg1 failed"
>>> pz @(Guards '[ '(PrintT "arg %d failed with value %d" Id,Gt 4), '(PrintT "%d %d" Id, Same 4)]) [17,3]
Fail "1 3"
>>> pz @(Msg "isbn10" (Resplit "-") >> Concat >> 'Just Unsnoc >> Map (ReadP Int (Singleton Id)) *** If (Singleton Id ==~ "X") 10 (ReadP Int (Singleton Id)) >> ZipWith (Fst * Snd) (1...10 >> Reverse) (Fst +: Snd) >> Sum >> Guard ("mod 0 oops") (Id Mod 11 == 0)) "0-306-40614-X"
Fail "mod 0 oops"
>>> pz @(Resplit "-" >> Concat >> 'Just Unsnoc >> Map (ReadP Int (Singleton Id)) *** If (Singleton Id ==~ "X") 10 (ReadP Int (Singleton Id)) >> ZipWith (Fst * Snd) (1...10 >> Reverse) (Fst +: Snd) >> Sum >> Guard ("mod 0 oops") (Id Mod 11 == 0)) "0-306-40611-X"
Val 132
>>> pz @(Msg "isbn13" (Resplit "-") >> Concat >> Map (ReadP Int (Singleton Id)) >> ZipWith (Fst * Snd) (Cycle 13 [1,3] >> Reverse) Id >> Sum >> '(Id,Id Mod 10) >> Guard (PrintT "sum=%d mod 10=%d" Id) (Snd == 0)) "978-0-306-40615-7"
Val (100,0)
>>> pz @(Resplit "-" >> Concat >> Map (ReadP Int (Singleton Id)) >> ZipWith (Fst * Snd) (Cycle 13 [1,3] >> Reverse) Id >> Sum >> '(Id,Id Mod 10) >> Guard (PrintT "sum=%d mod 10=%d" Id) (Snd == 0)) "978-0-306-40615-8"
Fail "sum=101 mod 10=1"
>>> pz @(Do '[Resplit "-", Concat, ZipWith (Fst * Snd) (Cycle 13 [1,3]) (Map (ReadP Int (Singleton Id))), Sum, Guard (PrintF "%d is not evenly divisible by 10" Id) (Id Mod 10 == 0)]) "978-0-7167-0344-9"
Fail "109 is not evenly divisible by 10"
>>> pz @(Do '[Resplit "-", Concat, ZipWith (Fst * Snd) (Cycle 13 [1,3]) (Map (ReadP Int (Singleton Id))), Sum, Guard (PrintF "%d is not evenly divisible by 10" Id) (Id Mod 10 == 0)]) "978-0-7167-0344-0"
Val 100

#### Instances

Instances details
 ([a] ~ x, GetLen ps, P (GuardsImpl (LenT ps) ps) x) => P (Guards ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (Guards ps) x Source # Methodseval :: MonadEval m => proxy (Guards ps) -> POpts -> x -> m (TT (PP (Guards ps) x)) Source # Show (Guards ps) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> Guards ps -> ShowS #show :: Guards ps -> String #showList :: [Guards ps] -> ShowS # type PP (Guards ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (Guards ps :: Type) x

data GuardsQuick (prt :: k) (ps :: [k1]) Source #

GuardsQuick contain a type level list of conditions and one of matching values: on no match will fail using the first parameter

>>> pz @(GuardsQuick (PrintT "arg %d failed with value %d" Id) '[Gt 4, Ge 3, Same 4]) [17,3,5]
Fail "arg 2 failed with value 5"
>>> pz @(GuardsQuick (PrintT "arg %d failed with value %d" Id) '[Gt 4, Ge 3, Same 4]) [17,3,5,99]
Fail "Guards:invalid length(4) expected 3"
>>> pl @(GuardsQuick (PrintT "guard(%d) %d is out of range" Id) '[Between 0 11 Id, Between 1 4 Id,Between 3 5 Id]) [10,2,5]
Present [10,2,5] (Guards(3))
Val [10,2,5]
>>> pl @(GuardsQuick (PrintT "guard(%d) %d is out of range" Id) '[Between 1 31 Id, Between 1 12 Id, Between 1990 2050 Id]) [31,11,1999]
Present [31,11,1999] (Guards(3))
Val [31,11,1999]
>>> pl @(GuardsQuick (PrintT "guard(%d) %d is out of range" Id) '[Between 1 31 Id, Between 1 12 Id, Between 1990 2050 Id]) [31,11]
Error Guards:invalid length(2) expected 3
Fail "Guards:invalid length(2) expected 3"
>>> pl @(GuardsQuick (PrintT "guard(%d) %d is out of range" Id) '[Between 1 31 Id, Between 1 12 Id, Between 1990 2050 Id]) [31,13,1999]
Error guard(1) 13 is out of range (Guard(1) 13)
Fail "guard(1) 13 is out of range"
>>> pl @(GuardsQuick (PrintT "guard(%d) %d is out of range" Id) '[Between 1 31 Id, Between 1 12 Id, Between 1990 2050 Id]) [0,44,1999]
Error guard(0) 0 is out of range (Guard(0) 0)
Fail "guard(0) 0 is out of range"
>>> pl @(GuardsQuick (PrintT "guard(%d) %d is out of range" Id) '[Between 1 31 Id, Between 1 12 Id, Between 1990 2050 Id]) [31,11,2000,1,2]
Error Guards:invalid length(5) expected 3
Fail "Guards:invalid length(5) expected 3"
>>> pl @(GuardsQuick (PrintT "guard(%d) err %03d" Id) '[W 'True, Ge 12, W 'False, Lt 2]) [1,2,-99,-999]
Error guard(1) err 002 (Guard(1) 2)
Fail "guard(1) err 002"
>>> pl @(GuardsQuick (PrintT "guard(%d) err %03d" Id) '[W 'True, Ge 12, W 'False, Lt 2]) [1,2,-99]
Error Guards:invalid length(3) expected 4
Fail "Guards:invalid length(3) expected 4"
>>> pl @(GuardsQuick (PrintT "guard(%d) err %03d" Id) '[W 'True, Ge 12, W 'True, Lt 2]) [1,22,-99,-999,1,1,2]
Error Guards:invalid length(7) expected 4
Fail "Guards:invalid length(7) expected 4"

#### Instances

Instances details
 P (GuardsQuickT prt ps) x => P (GuardsQuick prt ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (GuardsQuick prt ps) x Source # Methodseval :: MonadEval m => proxy (GuardsQuick prt ps) -> POpts -> x -> m (TT (PP (GuardsQuick prt ps) x)) Source # Show (GuardsQuick prt ps) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> GuardsQuick prt ps -> ShowS #show :: GuardsQuick prt ps -> String #showList :: [GuardsQuick prt ps] -> ShowS # type PP (GuardsQuick prt ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (GuardsQuick prt ps :: Type) x

data Guard prt p Source #

p is the predicate and on failure of the predicate runs prt

>>> pz @(Guard "expected > 3" (Gt 3)) 17
Val 17
>>> pz @(Guard "expected > 3" (Gt 3)) 1
Fail "expected > 3"
>>> pz @(Guard (PrintF "%d not > 3" Id) (Gt 3)) (-99)
Fail "-99 not > 3"
>>> pl @(Map (Guard "someval" (Lt 3) >> 'True)) [1 ..10]
Error someval(8) (Map(i=2, a=3) excnt=8)
Fail "someval(8)"
>>> pl @(Guard "someval" (Len == 2) >> (ShowP Id &&& Id)) ([] :: [Int])
Error someval (Guard | [])
Fail "someval"
>>> pl @(Guard "someval" (Len == 2) >> (Id &&& ShowP Id)) [2,3]
Present ([2,3],"[2,3]") ((>>) ([2,3],"[2,3]") | {'([2,3],"[2,3]")})
Val ([2,3],"[2,3]")
>>> pl @(Guard "someval" (Len == 2) >> (ShowP Id &&& Id)) [2,3,4]
Error someval (Guard | [2,3,4])
Fail "someval"
>>> pl @(Map (Guard "someval" (Lt 3) >> 'True)) [1 ..10]
Error someval(8) (Map(i=2, a=3) excnt=8)
Fail "someval(8)"
>>> pl @(Guard "oops" (Len > 2) >> Map Succ) [12,15,16]
Present [13,16,17] ((>>) [13,16,17] | {Map [13,16,17] | [12,15,16]})
Val [13,16,17]
>>> pl @(Guard "err" (Len > 2) >> Map Succ) [12]
Error err (Guard | [12])
Fail "err"
>>> pl @(Guard (PrintF "err found len=%d" Len) (Len > 5) >> Map Succ) [12,15,16]
Error err found len=3 (Guard | [12,15,16])
Fail "err found len=3"

#### Instances

Instances details
 (Show a, P prt a, PP prt a ~ String, P p a, PP p a ~ Bool) => P (Guard prt p :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (Guard prt p) a Source # Methodseval :: MonadEval m => proxy (Guard prt p) -> POpts -> a -> m (TT (PP (Guard prt p) a)) Source # Show (Guard prt p) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> Guard prt p -> ShowS #show :: Guard prt p -> String #showList :: [Guard prt p] -> ShowS # type PP (Guard prt p :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition type PP (Guard prt p :: Type) a = a

data ExitWhen prt p Source #

uses Guard but negates p

>>> pl @(HeadFail "failedn" Id &&& (Len == 1 >> ExitWhen "ExitWhen" Id) >> Fst) [3]
Error ExitWhen (Guard | True | True | '(,))
Fail "ExitWhen"
>>> pl @(Head &&& (Len == 1 >> Not Id >> ExitWhen "ExitWhen" Id) >> Fst) [3]
Present 3 ((>>) 3 | {Fst 3 | (3,False)})
Val 3
>>> pl @(Head &&& (Len == 1 >> ExitWhen "ExitWhen" (Not Id)) >> Fst) [3]
Present 3 ((>>) 3 | {Fst 3 | (3,True)})
Val 3
>>> pl @(ExitWhen "ExitWhen" (Len /= 1) >> Head) [3,1]
Error ExitWhen (Guard | [3,1])
Fail "ExitWhen"
>>> pl @(ExitWhen "ExitWhen" (Len /= 1) >> Head) [3]
Present 3 ((>>) 3 | {Head 3 | [3]})
Val 3
>>> pl @(ExitWhen "ExitWhen" (Len /= 1) >> Head >> Gt (20 -% 1)) [3]
True ((>>) True | {3 % 1 > (-20) % 1})
Val True
>>> pl @(ExitWhen "ExitWhen" (Len /= 1) >> Head >> Gt (20 -% 1)) [-23]
False ((>>) False | {(-23) % 1 > (-20) % 1})
Val False
>>> pl @(Map (ExitWhen "ExitWhen" (Gt 10) >> Gt 2)) [1..5]
Present [False,False,True,True,True] (Map [False,False,True,True,True] | [1,2,3,4,5])
Val [False,False,True,True,True]
>>> pl @(ExitWhen "err" (Len > 2) >> Map Succ) [12,15,16]
Error err (Guard | [12,15,16])
Fail "err"
>>> pl @(ExitWhen "err" (Len > 2) >> Map Succ) [12]
Present [13] ((>>) [13] | {Map [13] | [12]})
Val [13]

#### Instances

Instances details
 P (ExitWhenT prt p) x => P (ExitWhen prt p :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (ExitWhen prt p) x Source # Methodseval :: MonadEval m => proxy (ExitWhen prt p) -> POpts -> x -> m (TT (PP (ExitWhen prt p) x)) Source # Show (ExitWhen prt p) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> ExitWhen prt p -> ShowS #show :: ExitWhen prt p -> String #showList :: [ExitWhen prt p] -> ShowS # type PP (ExitWhen prt p :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (ExitWhen prt p :: Type) x

data GuardSimple p Source #

similar to Guard but uses the root message of the False predicate case as the failure message

>>> pz @(GuardSimple IsLuhn) [1..4]
Fail "(IsLuhn map=[2,2,6,4] sum=14 ret=4 | [1,2,3,4])"
>>> pz @(GuardSimple IsLuhn) [1,2,3,0]
Val [1,2,3,0]
>>> pz @(GuardSimple (Len > 30)) [1,2,3,0]
Fail "(4 > 30)"
>>> pl @(Map (GuardSimple (Lt 3) >> 'True)) [1 .. 10]
Error (3 < 3) | (4 < 3) | (5 < 3) | (6 < 3) | (7 < 3) | (8 < 3) | (9 < 3) | (10 < 3) (Map(i=2, a=3) excnt=8)
Fail "(3 < 3) | (4 < 3) | (5 < 3) | (6 < 3) | (7 < 3) | (8 < 3) | (9 < 3) | (10 < 3)"
>>> pl @(Map (GuardSimple (Ge 1) >> 'True)) [1 .. 10]
Present [True,True,True,True,True,True,True,True,True,True] (Map [True,True,True,True,True,True,True,True,True,True] | [1,2,3,4,5,6,7,8,9,10])
Val [True,True,True,True,True,True,True,True,True,True]
>>> pl @(Map (GuardSimple (Lt 3) >> 'True)) [1 .. 10]
Error (3 < 3) | (4 < 3) | (5 < 3) | (6 < 3) | (7 < 3) | (8 < 3) | (9 < 3) | (10 < 3) (Map(i=2, a=3) excnt=8)
Fail "(3 < 3) | (4 < 3) | (5 < 3) | (6 < 3) | (7 < 3) | (8 < 3) | (9 < 3) | (10 < 3)"

#### Instances

Instances details
 (Show a, P p a, PP p a ~ Bool) => P (GuardSimple p :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (GuardSimple p) a Source # Methodseval :: MonadEval m => proxy (GuardSimple p) -> POpts -> a -> m (TT (PP (GuardSimple p) a)) Source # Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> GuardSimple p -> ShowS #show :: GuardSimple p -> String #showList :: [GuardSimple p] -> ShowS # type PP (GuardSimple p :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition type PP (GuardSimple p :: Type) a = a

data GuardsN (n :: Nat) prt p Source #

leverages RepeatT for repeating predicates (passthrough method)

>>> pz @(GuardsN 4 (PrintT "id=%d must be between 0 and 255, found %d" Id) (0 <..> 0xff)) [121,33,7,256]
Fail "id=3 must be between 0 and 255, found 256"
>>> pz @(GuardsN 4 (PrintT "id=%d must be between 0 and 255, found %d" Id) (0 <..> 0xff)) [121,33,7,44]
Val [121,33,7,44]
>>> pl @(GuardsN 4 (PrintT "guard(%d) %d is out of range" Id) (0 <..> 0xff)) [1,2,3,4]
Present [1,2,3,4] (Guards(4))
Val [1,2,3,4]
>>> pl @(GuardsN 4 (PrintT "guard(%d) %d is out of range" Id) (0 <..> 0xff)) [1,2,3,4,5]
Error Guards:invalid length(5) expected 4
Fail "Guards:invalid length(5) expected 4"
>>> pl @(GuardsN 4 (PrintT "guard(%d) %d is out of range" Id) (0 <..> 0xff)) [1,2,3]
Error Guards:invalid length(3) expected 4
Fail "Guards:invalid length(3) expected 4"
>>> pl @(Resplit "\\." >> Map (ReadP Int Id) >> GuardsN 4 (PrintT "invalid pos=%d val=%d" Id) (0 <..> 0xff)) "13.22.44.1231"
Error invalid pos=3 val=1231 (Guard(3) 1231 | [13,22,44,1231])
Fail "invalid pos=3 val=1231"

#### Instances

Instances details
 (x ~ [a], P (GuardsNT prt n p) x) => P (GuardsN prt n p :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (GuardsN prt n p) x Source # Methodseval :: MonadEval m => proxy (GuardsN prt n p) -> POpts -> x -> m (TT (PP (GuardsN prt n p) x)) Source # Show (GuardsN n prt p) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> GuardsN n prt p -> ShowS #show :: GuardsN n prt p -> String #showList :: [GuardsN n prt p] -> ShowS # type PP (GuardsN prt n p :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (GuardsN prt n p :: Type) x

data GuardsDetail prt (ps :: [(k0, k1)]) Source #

if a predicate fails then then the corresponding symbol and value will be passed to the print function

>>> pz @(GuardsDetail "%s invalid: found %d" '[ '("hours", Between 0 23 Id),'("minutes",Between 0 59 Id),'("seconds",Between 0 59 Id)]) [13,59,61]
Fail "seconds invalid: found 61"
>>> pz @(GuardsDetail "%s invalid: found %d" '[ '("hours", Between 0 23 Id),'("minutes",Between 0 59 Id),'("seconds",Between 0 59 Id)]) [27,59,12]
Fail "hours invalid: found 27"
>>> pz @(GuardsDetail "%s invalid: found %d" '[ '("hours", Between 0 23 Id),'("minutes",Between 0 59 Id),'("seconds",Between 0 59 Id)]) [23,59,12]
Val [23,59,12]

#### Instances

Instances details
 P (GuardsDetailT prt ps) x => P (GuardsDetail prt ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (GuardsDetail prt ps) x Source # Methodseval :: MonadEval m => proxy (GuardsDetail prt ps) -> POpts -> x -> m (TT (PP (GuardsDetail prt ps) x)) Source # Show (GuardsDetail prt ps) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> GuardsDetail prt ps -> ShowS #show :: GuardsDetail prt ps -> String #showList :: [GuardsDetail prt ps] -> ShowS # type PP (GuardsDetail prt ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (GuardsDetail prt ps :: Type) x

data GuardBool prt p Source #

boolean guard

>>> pl @(GuardBool (PrintF "bad length = %d" Len) (Len > 9)) [3..8]
Error bad length = 6 (GuardBool (6 > 9))

#### Instances

Instances details
 (P prt a, PP prt a ~ String, P p a, PP p a ~ Bool) => P (GuardBool prt p :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (GuardBool prt p) a Source # Methodseval :: MonadEval m => proxy (GuardBool prt p) -> POpts -> a -> m (TT (PP (GuardBool prt p) a)) Source # Show (GuardBool prt p) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> GuardBool prt p -> ShowS #show :: GuardBool prt p -> String #showList :: [GuardBool prt p] -> ShowS # type PP (GuardBool prt p :: Type) a Source # Instance detailsDefined in Predicate.Data.Condition type PP (GuardBool prt p :: Type) a = Bool

data Bools (ps :: [(k, k1)]) Source #

boolean guard which checks a given a list of predicates against the list of values

>>> pl @(Bools '[ '(W "hh",Between 0 23 Id), '(W "mm",Between 0 59 Id), '(PrintT "<<<%d %d>>>" Id,Between 0 59 Id) ]) [12,93,14]
Error Bool(1) [mm] (93 <= 59)
Fail "Bool(1) [mm] (93 <= 59)"
>>> pl @(Bools '[ '(W "hh",Between 0 23 Id), '(W "mm",Between 0 59 Id), '(PrintT "<<<%d %d>>>" Id,Between 0 59 Id) ]) [12,13,94]
Error Bool(2) [<<<2 94>>>] (94 <= 59)
Fail "Bool(2) [<<<2 94>>>] (94 <= 59)"
>>> pl @(Bools '[ '(W "hh",Between 0 23 Id), '(W "mm",Between 0 59 Id), '(PrintT "<<<%d %d>>>" Id,Between 0 59 Id) ]) [12,13,14]
True (Bools)
Val True
>>> pl @(Bools '[ '("hours",Between 0 23 Id), '("minutes",Between 0 59 Id), '("seconds",Between 0 59 Id)]) [12,13,14]
True (Bools)
Val True
>>> pl @(Bools '[ '("hours",Between 0 23 Id), '("minutes",Between 0 59 Id), '("seconds",Between 0 59 Id)]) [12,60,14]
Error Bool(1) [minutes] (60 <= 59)
Fail "Bool(1) [minutes] (60 <= 59)"
>>> pl @(Bools '[ '("hours",Between 0 23 Id), '("minutes",Between 0 59 Id), '("seconds",Between 0 59 Id)]) [12,60,14,20]
Error Bools:invalid length(4) expected 3
Fail "Bools:invalid length(4) expected 3"

#### Instances

Instances details
 ([a] ~ x, GetLen ps, P (BoolsImpl (LenT ps) ps) x, PP (BoolsImpl (LenT ps) ps) x ~ Bool) => P (Bools ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (Bools ps) x Source # Methodseval :: MonadEval m => proxy (Bools ps) -> POpts -> x -> m (TT (PP (Bools ps) x)) Source # Show (Bools ps) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> Bools ps -> ShowS #show :: Bools ps -> String #showList :: [Bools ps] -> ShowS # type PP (Bools ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (Bools ps :: Type) x = Bool

data BoolsQuick (prt :: k) (ps :: [k1]) Source #

boolean guard which checks a given a list of predicates against the list of values

>>> pl @(BoolsQuick "abc" '[Between 0 23 Id, Between 0 59 Id, Between 0 59 Id]) [12,13,14]
True (Bools)
Val True
>>> pl @(BoolsQuick (PrintT "id=%d val=%d" Id) '[Between 0 23 Id, Between 0 59 Id, Between 0 59 Id]) [12,13,14]
True (Bools)
Val True
>>> pl @(BoolsQuick (PrintT "id=%d val=%d" Id) '[Between 0 23 Id, Between 0 59 Id, Between 0 59 Id]) [12,13,99]
Error Bool(2) [id=2 val=99] (99 <= 59)
Fail "Bool(2) [id=2 val=99] (99 <= 59)"

#### Instances

Instances details
 (PP (Bools (ToGuardsT prt ps)) x ~ Bool, P (BoolsQuickT prt ps) x) => P (BoolsQuick prt ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (BoolsQuick prt ps) x Source # Methodseval :: MonadEval m => proxy (BoolsQuick prt ps) -> POpts -> x -> m (TT (PP (BoolsQuick prt ps) x)) Source # Show (BoolsQuick prt ps) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> BoolsQuick prt ps -> ShowS #show :: BoolsQuick prt ps -> String #showList :: [BoolsQuick prt ps] -> ShowS # type PP (BoolsQuick prt ps :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (BoolsQuick prt ps :: Type) x = Bool

data BoolsN prt (n :: Nat) (p :: k1) Source #

leverages RepeatT for repeating predicates (passthrough method)

>>> pl @(BoolsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (0 <..> 0xff)) [121,33,7,256]
Error Bool(3) [id=3 must be between 0 and 255, found 256] (256 <= 255)
Fail "Bool(3) [id=3 must be between 0 and 255, found 256] (256 <= 255)"
>>> pl @(BoolsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (0 <..> 0xff)) [121,33,7,44]
True (Bools)
Val True

#### Instances

Instances details
 (x ~ [a], P (BoolsNT prt n p) x) => P (BoolsN prt n p :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition Associated Typestype PP (BoolsN prt n p) x Source # Methodseval :: MonadEval m => proxy (BoolsN prt n p) -> POpts -> x -> m (TT (PP (BoolsN prt n p) x)) Source # Show (BoolsN prt n p) Source # Instance detailsDefined in Predicate.Data.Condition MethodsshowsPrec :: Int -> BoolsN prt n p -> ShowS #show :: BoolsN prt n p -> String #showList :: [BoolsN prt n p] -> ShowS # type PP (BoolsN prt n p :: Type) x Source # Instance detailsDefined in Predicate.Data.Condition type PP (BoolsN prt n p :: Type) x = Bool

## type families

type family ToGuardsT (prt :: k) (os :: [k1]) :: [(k, k1)] where ... Source #

expands out the condition parameter used by Guards and Bools

Equations

 ToGuardsT prt '[] = TypeError ('Text "ToGuardsT cannot be empty: prt=" :<>: 'ShowType prt) ToGuardsT prt '[p] = '(prt, p) ': '[] ToGuardsT prt (p ': ps) = '(prt, p) ': ToGuardsT prt ps

type family ToGuardsDetailT (prt :: k1) (os :: [(k2, k3)]) :: [(Type, k3)] where ... Source #

expands out the condition parameter used by GuardsDetail

Equations

 ToGuardsDetailT prt '['(s, p)] = '(PrintT prt '(s, Snd), p) ': '[] ToGuardsDetailT prt ('(s, p) ': ps) = '(PrintT prt '(s, Snd), p) ': ToGuardsDetailT prt ps ToGuardsDetailT _prt '[] = TypeError ('Text "ToGuardsDetailT cannot be empty")