Safe Haskell | None |
---|---|
Language | Haskell2010 |
A data type with ten nullary constructors [0-9] and combinators.
- data Digit
- foldDigit :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> Digit -> a
- class HasDigit a where
- class D0 d where
- x0 :: D0 d => d
- class D1 d where
- x1 :: D1 d => d
- class D2 d where
- x2 :: D2 d => d
- class D3 d where
- x3 :: D3 d => d
- class D4 d where
- x4 :: D4 d => d
- class D5 d where
- x5 :: D5 d => d
- class D6 d where
- x6 :: D6 d => d
- class D7 d where
- x7 :: D7 d => d
- class D8 d where
- x8 :: D8 d => d
- class D9 d where
- x9 :: D9 d => d
- digit :: Integral a => Prism' a Digit
- digitC :: Prism' Char Digit
- digitlist :: Integral a => Prism' a [Digit]
- mod10 :: Integral a => a -> Digit
- divMod10 :: Integral a => a -> (a, Digit)
- parsedigit :: (Monad p, CharParsing p) => p Digit
- parsedigitlist :: (Monad p, CharParsing p) => p [Digit]
- parsedigits :: (Monad p, CharParsing p) => p Digits
- parsedigitlist1 :: (Monad p, CharParsing p) => p (NonEmpty Digit)
- skipdigitlist :: (Monad p, CharParsing p) => p ()
- skipdigitlist1 :: (Monad p, CharParsing p) => p ()
- parsenotdigit :: CharParsing p => p Char
- parsenotdigits :: CharParsing p => p String
- parsenotdigits1 :: CharParsing p => p String
- skipnotdigits :: CharParsing p => p ()
- skipnotdigits1 :: CharParsing p => p ()
- digitQ :: QuasiQuoter
- data Digits
- digits :: Integral a => Prism' a Digits
- digitsI :: Iso' [Digit] Digits
- digitsS :: Prism' String Digits
- (/+/) :: Digit -> Digit -> (Digit, Digit)
- (.+.) :: Digits -> Digits -> Digits
- (.*.) :: Digits -> Digits -> Digits
- mantissa :: Floating a => Digits -> a
Data type
A data type with ten nullary constructors.
Destructors
:: a | Zero. |
-> a | One. |
-> a | Two. |
-> a | Three. |
-> a | Four. |
-> a | Five. |
-> a | Six. |
-> a | Seven. |
-> a | Eight. |
-> a | Nine. |
-> Digit | The digit to fold. |
-> a |
Catamorphism for Digit
.
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D0 == q0
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D1 == q1
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D2 == q2
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D3 == q3
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D4 == q4
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D5 == q5
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D6 == q6
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D7 == q7
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D8 == q8
foldDigit q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 D9 == q9
Lenses
Prisms
digit :: Integral a => Prism' a Digit Source #
A prism for using Int
as Digit
.
>>>
5 ^? digit
Just 5
>>>
0 ^? digit
Just 0
>>>
9 ^? digit
Just 9
>>>
10 ^? digit
Nothing
>>>
(-5) ^? digit
Nothing
>>>
digit # D5
5
>>>
digit # D9
9
>>>
digit # D0
0
digitC :: Prism' Char Digit Source #
A prism for using Char
as Digit
.
>>>
'5' ^? digitC
Just 5
>>>
'0' ^? digitC
Just 0
>>>
'9' ^? digitC
Just 9
>>>
'a' ^? digitC
Nothing
>>>
'@' ^? digitC
Nothing
>>>
digitC # D5
'5'
>>>
digitC # D9
'9'
>>>
digitC # D0
'0'
digitlist :: Integral a => Prism' a [Digit] Source #
A prism for the list of digits in an integer
>>>
1234 ^? digitlist
Just [1,2,3,4]
>>>
0 ^? digitlist
Just []
>>>
1 ^? digitlist
Just [1]
>>>
90 ^? digitlist
Just [9,0]
>>>
05 ^? digitlist
Just [5]
>>>
105 ^? digitlist
Just [1,0,5]
>>>
(-1) ^? digitlist
Nothing
λ> digitlist # [D0] 0
>>>
digitlist # [D0, D1]
1
>>>
digitlist # [D1]
1
>>>
digitlist # [D1, D2, D3]
123
>>>
digitlist # [D1, D0, D3]
103
>>>
digitlist # [D1, D0, D3, D0]
1030
mod operations
mod10 :: Integral a => a -> Digit Source #
Modulus with 10.
>>>
mod10 0
0
>>>
mod10 1
1
>>>
mod10 8
8
>>>
mod10 9
9
>>>
mod10 10
0
>>>
mod10 90
0
>>>
mod10 91
1
>>>
mod10 (-1)
9
divMod10 :: Integral a => a -> (a, Digit) Source #
Division/modulus with 10.
>>>
divMod10 0
(0,0)
>>>
divMod10 1
(0,1)
>>>
divMod10 8
(0,8)
>>>
divMod10 9
(0,9)
>>>
divMod10 10
(1,0)
>>>
divMod10 90
(9,0)
>>>
divMod10 91
(9,1)
>>>
divMod10 (-1)
(-1,9)
Parsers
parsedigit :: (Monad p, CharParsing p) => p Digit Source #
parsedigitlist :: (Monad p, CharParsing p) => p [Digit] Source #
parsedigits :: (Monad p, CharParsing p) => p Digits Source #
parsedigitlist1 :: (Monad p, CharParsing p) => p (NonEmpty Digit) Source #
skipdigitlist :: (Monad p, CharParsing p) => p () Source #
skipdigitlist1 :: (Monad p, CharParsing p) => p () Source #
parsenotdigit :: CharParsing p => p Char Source #
parsenotdigits :: CharParsing p => p String Source #
parsenotdigits1 :: CharParsing p => p String Source #
skipnotdigits :: CharParsing p => p () Source #
skipnotdigits1 :: CharParsing p => p () Source #
Quasi-Quoters
digitQ :: QuasiQuoter Source #
A QuasiQuoter for any range of Digit
.
- digitQ|4|
- :: Digit 4
named [digitQ|4|] = "four" named [digitQ|$x|] = "not four, " ++ show x ++ " instead"
mod10D x = let y = mod x 10 in [digitQ|$y|]
Digits
(/+/) :: Digit -> Digit -> (Digit, Digit) Source #
>>>
D0 /+/ D0
(0,0)
>>>
D0 /+/ D1
(0,1)
>>>
D1 /+/ D0
(0,1)
>>>
D4 /+/ D5
(0,9)
>>>
D5 /+/ D5
(1,0)
>>>
D5 /+/ D6
(1,1)
>>>
D8 /+/ D7
(1,5)
>>>
D9 /+/ D9
(1,8)
(.+.) :: Digits -> Digits -> Digits Source #
>>>
Digits [x2] .+. Digits [x1, x0]
Digits [1,2]
>>>
Digits [x1, x2, x3] .+. Digits [x4, x5, x6]
Digits [5,7,9]