Safe Haskell | None |
---|---|
Language | Haskell2010 |
Contains prepackaged 4-tuples to use with Refined3
Synopsis
- datetime1 :: Proxy (DateTime1 t)
- type DateTime1 (t :: Type) = '(Dtip t, Dtop, Dtfmt, String)
- hms :: Proxy Hms
- type Hms = '(Hmsip, Hmsop >> True, Hmsfmt, String)
- type HmsRE = "^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$"
- type Hmsip = Map (ReadP Int) (Resplit ":" Id)
- type Hmsop = GuardsDetail "%s invalid: found %d" '['("hours", Between 0 23), '("minutes", Between 0 59), '("seconds", Between 0 59)]
- type Hmsfmt = Printfnt 3 "%02d:%02d:%02d"
- type DateFmts = '["%Y-%m-%d", "%m/%d/%y", "%B %d %Y"]
- type DateN = '(ParseTimes Day DateFmts Id, True, FormatTimeP "%Y-%m-%d" Id, String)
- type DateTimeFmts = '["%Y-%m-%d %H:%M:%S", "%m/%d/%y %H:%M:%S", "%B %d %Y %H:%M:%S", "%Y-%m-%dT%H:%M:%S"]
- type DateTimeN = '(ParseTimes UTCTime DateTimeFmts Id, True, FormatTimeP "%Y-%m-%d %H:%M:%S" Id, String)
- daten :: Proxy DateN
- datetimen :: Proxy DateTimeN
- ccn :: Proxy (Ccn ns)
- cc11 :: Proxy (Ccn '[4, 4, 3])
- type Ccn (ns :: [Nat]) = '(Ccip, Ccop (SumT ns), Ccfmt ns, String)
- type CC11 = Ccn '[4, 4, 3]
- type LuhnR (n :: Nat) = MakeR3 (LuhnT n)
- type LuhnT (n :: Nat) = '(Map (ReadP Int) (Ones Id), Guard (Printfn "incorrect number of digits found %d but expected %d in [%s]" (TupleI '[Len, W n, ShowP Id])) (Len >> Same n) >> (GuardSimple (Luhn Id) >> True), ConcatMap (ShowP Id) Id, String)
- ssn :: Proxy Ssn
- type Ssn = '(Ssnip, Ssnop, Ssnfmt, String)
- ip :: Proxy Ip
- type Ip = '(Ipip, Ipop, Ipfmt, String)
- type OctetRE = "(25[0-5]|2[0..4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
- type Ip4StrictRE = ("^" `AppendSymbol` IntersperseT "\\." (RepeatT 4 OctetRE)) `AppendSymbol` "$"
- basen :: Proxy (BaseN n)
- base16 :: Proxy (BaseN 16)
- basen' :: Proxy (BaseN' n p)
- type BaseN (n :: Nat) = BaseN' n True
- type BaseN' (n :: Nat) p = '(ReadBase Int n, p, ShowBase n, String)
- type BaseIJ (i :: Nat) (j :: Nat) = BaseIJ' i j True
- type BaseIJ' (i :: Nat) (j :: Nat) p = '(ReadBase Int i >> ShowBase j, p, ReadBase Int j >> ShowBase i, String)
- readshow :: Proxy (ReadShow t)
- type ReadShow (t :: Type) = '(ReadP t, True, ShowP Id, String)
- type ReadShowR (t :: Type) = MakeR3 (ReadShow t)
- readshow' :: Proxy (ReadShow' t p)
- type ReadShow' (t :: Type) p = '(ReadP t, p, ShowP Id, String)
- type ReadShowR' (t :: Type) p = MakeR3 (ReadShow' t p)
- between :: Proxy (BetweenN m n)
- type BetweenR m n = RefinedEmulate (Between m n) Int
- type BetweenN m n = '(Id, Between m n, Id, Int)
- ok :: Proxy (Ok t)
- type Ok (t :: Type) = '(Id, True, Id, t)
- type OkR (t :: Type) = MakeR3 (Ok t)
- oknot :: Proxy (OkNot t)
- type OkNot (t :: Type) = '(Id, False, Id, t)
- type OkNotR (t :: Type) = MakeR3 (OkNot t)
date time checkers
datetime1 :: Proxy (DateTime1 t) Source #
read in a valid datetime
>>>
prtEval3P (datetime1 @LocalTime) ol "2018-09-14 02:57:04"
Right (Refined3 {r3In = 2018-09-14 02:57:04, r3Out = "2018-09-14 02:57:04"})
>>>
prtEval3P (datetime1 @LocalTime) ol "2018-09-14 99:98:97"
Left Step 2. Failed Boolean Check(op) | hours invalid: found 99
>>>
prtEval3P (datetime1 @LocalTime) ol "2018-09-14 23:01:97"
Left Step 2. Failed Boolean Check(op) | seconds invalid: found 97
>>>
prtEval3P (Proxy @(DateTime1 UTCTime)) ol "2018-09-14 99:98:97"
Right (Refined3 {r3In = 2018-09-18 04:39:37 UTC, r3Out = "2018-09-18 04:39:37"})
read in a time and validate it
>>>
prtEval3P hms ol "23:13:59"
Right (Refined3 {r3In = [23,13,59], r3Out = "23:13:59"})
>>>
prtEval3P hms ol "23:13:60"
Left Step 2. Failed Boolean Check(op) | seconds invalid: found 60
>>>
prtEval3P hms ol "26:13:59"
Left Step 2. Failed Boolean Check(op) | hours invalid: found 26
type Hmsop = GuardsDetail "%s invalid: found %d" '['("hours", Between 0 23), '("minutes", Between 0 59), '("seconds", Between 0 59)] Source #
type DateTimeFmts = '["%Y-%m-%d %H:%M:%S", "%m/%d/%y %H:%M:%S", "%B %d %Y %H:%M:%S", "%Y-%m-%dT%H:%M:%S"] Source #
type DateTimeN = '(ParseTimes UTCTime DateTimeFmts Id, True, FormatTimeP "%Y-%m-%d %H:%M:%S" Id, String) Source #
credit cards
type LuhnT (n :: Nat) = '(Map (ReadP Int) (Ones Id), Guard (Printfn "incorrect number of digits found %d but expected %d in [%s]" (TupleI '[Len, W n, ShowP Id])) (Len >> Same n) >> (GuardSimple (Luhn Id) >> True), ConcatMap (ShowP Id) Id, String) Source #
Luhn check
>>>
prtEval3P (Proxy @(LuhnT 4)) ol "1230"
Right (Refined3 {r3In = [1,2,3,0], r3Out = "1230"})
>>>
prtEval3P (Proxy @(LuhnT 4)) ol "1234"
Left Step 2. Failed Boolean Check(op) | Luhn map=[4,6,2,2] sum=14 ret=4 | [1,2,3,4]
uses builtin Luhn
ssn
type Ssn = '(Ssnip, Ssnop, Ssnfmt, String) Source #
read in an ssn
>>>
prtEval3P ssn ol "134-01-2211"
Right (Refined3 {r3In = [134,1,2211], r3Out = "134-01-2211"})
>>>
prtEval3P ssn ol "666-01-2211"
Left Step 2. Failed Boolean Check(op) | number for group 1 invalid: found 666
>>>
prtEval3P ssn ol "666-01-2211"
Left Step 2. Failed Boolean Check(op) | number for group 1 invalid: found 666
>>>
prtEval3P ssn ol "667-00-2211"
Left Step 2. Failed Boolean Check(op) | number for group 2 invalid: found 0
>>>
prtEval3P ssn ol "666-01-2211"
Left Step 2. Failed Boolean Check(op) | number for group 1 invalid: found 666
>>>
prtEval3P ssn ol "991-22-9999"
Left Step 2. Failed Boolean Check(op) | number for group 1 invalid: found 991
ipv4
type Ip = '(Ipip, Ipop, Ipfmt, String) Source #
read in an ipv4 address and validate it
>>>
prtEval3P ip ol "001.223.14.1"
Right (Refined3 {r3In = [1,223,14,1], r3Out = "001.223.014.001"})
>>>
prtEval3P ip ol "001.223.14.999"
Left Step 2. Failed Boolean Check(op) | guard(4) octet out of range 0-255 found 999
>>>
prtEval3P ip ol "001.223.14.999.1"
Left Step 1. Initial Conversion(ip) Failed | Regex no results
>>>
prtEval3P ip ol "001.257.14.1"
Left Step 2. Failed Boolean Check(op) | guard(2) octet out of range 0-255 found 257
type Ip4StrictRE = ("^" `AppendSymbol` IntersperseT "\\." (RepeatT 4 OctetRE)) `AppendSymbol` "$" Source #
base n
type BaseN (n :: Nat) = BaseN' n True Source #
convert a string from a given base 'i' and store it internally as an base 10 integer
>>>
prtEval3P base16 ol "00fe"
Right (Refined3 {r3In = 254, r3Out = "fe"})
>>>
prtEval3P (basen' @16 @(Between 100 400)) ol "00fe"
Right (Refined3 {r3In = 254, r3Out = "fe"})
>>>
prtEval3P (basen' @16 @(GuardSimple (Id < 400) >> 'True)) ol "f0fe"
Left Step 2. Failed Boolean Check(op) | 61694 < 400
type BaseIJ (i :: Nat) (j :: Nat) = BaseIJ' i j True Source #
convert a string from a given base 'i' and store it internally as a base 'j' string
>>>
prtEval3P (Proxy @(BaseIJ 16 2)) ol "fe"
Right (Refined3 {r3In = "11111110", r3Out = "fe"})
>>>
prtEval3P (Proxy @(BaseIJ 16 2)) ol "fge"
Left Step 1. Initial Conversion(ip) Failed | invalid base 16
>>>
prtEval3P (Proxy @(BaseIJ' 16 2 (GuardSimple (ReadBase Int 2 < 1000) >> 'True))) ol "ffe"
Left Step 2. Failed Boolean Check(op) | 4094 < 1000
type BaseIJ' (i :: Nat) (j :: Nat) p = '(ReadBase Int i >> ShowBase j, p, ReadBase Int j >> ShowBase i, String) Source #
read / show
type ReadShow (t :: Type) = '(ReadP t, True, ShowP Id, String) Source #
take any valid Read/Show instance and turn it into a valid Refined3
>>>
:m + Data.Ratio
>>>
prtEval3P (readshow @Rational) ol "13 % 3"
Right (Refined3 {r3In = 13 % 3, r3Out = "13 % 3"})
>>>
prtEval3P (readshow @Rational) ol "13x % 3"
Left Step 1. Initial Conversion(ip) Failed | ReadP Ratio Integer (13x % 3) failed
>>>
prtEval3P (readshow' @Rational @(Between (3 % 1) (5 % 1))) ol "13 % 3"
Right (Refined3 {r3In = 13 % 3, r3Out = "13 % 3"})
>>>
prtEval3P (Proxy @(ReadShow' Rational (Between (11 %- 2) (3 %- 1)))) ol "-13 % 3"
Right (Refined3 {r3In = (-13) % 3, r3Out = "(-13) % 3"})
>>>
prtEval3P (Proxy @(ReadShow' Rational (Id > (15 % 1)))) ol "13 % 3"
Left Step 2. False Boolean Check(op) | FalseP
>>>
prtEval3P (Proxy @(ReadShow' Rational (Guard (Printf "invalid=%3.2f" (FromRational Double Id)) (Id > (15 % 1)) >> 'True))) ol "13 % 3"
Left Step 2. Failed Boolean Check(op) | invalid=4.33
>>>
prtEval3P (Proxy @(ReadShow' Rational (Id > (11 % 1)))) ol "13 % 3"
Left Step 2. False Boolean Check(op) | FalseP
>>>
let tmString = "2018-10-19 14:53:11.5121359 UTC"
>>>
let tm = read tmString :: UTCTime
>>>
prtEval3P (readshow @UTCTime) ol tmString
Right (Refined3 {r3In = 2018-10-19 14:53:11.5121359 UTC, r3Out = "2018-10-19 14:53:11.5121359 UTC"})
>>>
:m + Data.Aeson
>>>
prtEval3P (readshow @Value) ol "String \"jsonstring\""
Right (Refined3 {r3In = String "jsonstring", r3Out = "String \"jsonstring\""})
>>>
prtEval3P (readshow @Value) ol "Number 123.4"
Right (Refined3 {r3In = Number 123.4, r3Out = "Number 123.4"})
between
between :: Proxy (BetweenN m n) Source #
ensures that two numbers are in a given range (emulates Refined
)
>>>
prtEval3P (between @10 @16) ol 14
Right (Refined3 {r3In = 14, r3Out = 14})
>>>
prtEval3P (between @10 @16) ol 17
Left Step 2. False Boolean Check(op) | FalseP
>>>
prtEval3P (between @10 @16) o0 17
Left Step 2. False Boolean Check(op) | FalseP *** Step 1. Success Initial Conversion(ip) [17] *** P Id 17 *** Step 2. False Boolean Check(op) *** False True && False | +- True 17 >= 10 | | | +- P I | | | `- P '10 | `- False 17 <= 16 | +- P I | `- P '16