| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Taiwan.ID
Synopsis
- data ID = ID {}
- fromSymbol :: forall (s :: Symbol). ValidID s => ID
- fromText :: Text -> Either FromTextError ID
- data FromTextError
- toText :: ID -> Text
- checksum :: ID -> Digit
- generate :: MonadRandom m => m ID
- getGender :: ID -> Gender
- getIssuer :: ID -> Issuer
- getRegion :: ID -> Region
- setGender :: Gender -> ID -> ID
- setIssuer :: Issuer -> ID -> ID
- setRegion :: Region -> ID -> ID
Type
Represents a valid 10-digit uniform identification number of the form
A123456789.
By construction, invalid identification numbers are not representable by this data type.
To guarantee correctness, an ID value does not store the terminal
checksum digit of the identification number it represents.
To compute the checksum digit, use checksum.
Constructors
| ID | |
Instances
Construction
fromSymbol :: forall (s :: Symbol). ValidID s => ID Source #
Constructs an ID from a type-level textual symbol.
The symbol must be exactly 10 characters in length and of the form
A123456789:
>>>ID.fromSymbol @"A123456789"ID.fromSymbol @"A123456789"
More precisely:
- the symbol must match the regular expression
^[A-Z][1289][0-9]{8}$ - the resultant ID must have a valid checksum.
Failure to satisfy these constraints will result in one of the following type errors:
Invalid lengths
>>>ID.fromSymbol @"A12345678"... ... An ID must have exactly 10 characters. ...
Invalid checksums
>>>ID.fromSymbol @"A123456780"... ... ID has invalid checksum. ...
Invalid characters
On detection of an invalid character, the resulting type error reports both the position of the character and the set of characters permitted at that position.
>>>ID.fromSymbol @"_123456789"... • "_123456789" ^ Character at this position must be an uppercase letter. ...
>>>ID.fromSymbol @"A_23456789"... • "A_23456789" ^ Character at this position must be a digit from the set {1, 2, 8, 9}. ...
>>>ID.fromSymbol @"A1_3456789"... • "A1_3456789" ^ Character at this position must be a digit in the range [0 .. 9]. ...
Missing or empty symbols
>>>ID.fromSymbol... ... Expected a type-level symbol of the form "A123456789". ...
>>>ID.fromSymbol @""... ... Expected a type-level symbol of the form "A123456789". ...
fromText :: Text -> Either FromTextError ID Source #
Attempts to construct an ID from Text.
The input must be exactly 10 characters in length and of the form
A123456789:
>>>ID.fromText "A123456789"Right (ID.fromSymbol @"A123456789")
More precisely, the input must match the regular expression
^[A-Z][1289][0-9]{8}$, and the resultant ID must have a valid
checksum.
This function satisfies the following law:
fromText(toTexti)==Righti
data FromTextError Source #
Constructors
| InvalidChar CharIndex CharSet | Indicates that the input text contains a character that is not allowed. |
| InvalidChecksum | Indicates that the parsed identification number has an invalid checksum. |
| InvalidLength | Indicates that the input text has an invalid length. |
Instances
| Eq FromTextError Source # | |
Defined in Taiwan.ID Methods (==) :: FromTextError -> FromTextError -> Bool # (/=) :: FromTextError -> FromTextError -> Bool # | |
| Ord FromTextError Source # | |
Defined in Taiwan.ID Methods compare :: FromTextError -> FromTextError -> Ordering # (<) :: FromTextError -> FromTextError -> Bool # (<=) :: FromTextError -> FromTextError -> Bool # (>) :: FromTextError -> FromTextError -> Bool # (>=) :: FromTextError -> FromTextError -> Bool # max :: FromTextError -> FromTextError -> FromTextError # min :: FromTextError -> FromTextError -> FromTextError # | |
| Show FromTextError Source # | |
Defined in Taiwan.ID Methods showsPrec :: Int -> FromTextError -> ShowS # show :: FromTextError -> String # showList :: [FromTextError] -> ShowS # | |