digit-0.2.9: A data-type representing digits 0-9 and other combinations

Safe HaskellNone
LanguageHaskell2010

Data.Digit

Contents

Description

A data type with ten nullary constructors [0-9] and combinators.

Synopsis

Data type

data Digit Source #

A data type with ten nullary constructors.

Instances

Bounded Digit Source # 
Enum Digit Source # 
Eq Digit Source # 

Methods

(==) :: Digit -> Digit -> Bool #

(/=) :: Digit -> Digit -> Bool #

Data Digit Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Digit -> c Digit #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Digit #

toConstr :: Digit -> Constr #

dataTypeOf :: Digit -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Digit) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Digit) #

gmapT :: (forall b. Data b => b -> b) -> Digit -> Digit #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Digit -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Digit -> r #

gmapQ :: (forall d. Data d => d -> u) -> Digit -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Digit -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Digit -> m Digit #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Digit -> m Digit #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Digit -> m Digit #

Ord Digit Source # 

Methods

compare :: Digit -> Digit -> Ordering #

(<) :: Digit -> Digit -> Bool #

(<=) :: Digit -> Digit -> Bool #

(>) :: Digit -> Digit -> Bool #

(>=) :: Digit -> Digit -> Bool #

max :: Digit -> Digit -> Digit #

min :: Digit -> Digit -> Digit #

Show Digit Source # 

Methods

showsPrec :: Int -> Digit -> ShowS #

show :: Digit -> String #

showList :: [Digit] -> ShowS #

D9 Digit Source # 

Methods

d9 :: Prism' Digit () Source #

D8 Digit Source # 

Methods

d8 :: Prism' Digit () Source #

D7 Digit Source # 

Methods

d7 :: Prism' Digit () Source #

D6 Digit Source # 

Methods

d6 :: Prism' Digit () Source #

D5 Digit Source # 

Methods

d5 :: Prism' Digit () Source #

D4 Digit Source # 

Methods

d4 :: Prism' Digit () Source #

D3 Digit Source # 

Methods

d3 :: Prism' Digit () Source #

D2 Digit Source # 

Methods

d2 :: Prism' Digit () Source #

D1 Digit Source # 

Methods

d1 :: Prism' Digit () Source #

D0 Digit Source # 

Methods

d0 :: Prism' Digit () Source #

HasDigit Digit Source # 
Cons Digits Digits Digit Digit Source # 
Snoc Digits Digits Digit Digit Source # 
Each Digits Digits Digit Digit Source # 

Destructors

foldDigit Source #

Arguments

:: 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

class HasDigit a where Source #

Minimal complete definition

hasdigit

Prisms

class D0 d where Source #

Minimal complete definition

d0

Methods

d0 :: Prism' d () Source #

Instances

D0 Digit Source # 

Methods

d0 :: Prism' Digit () Source #

x0 :: D0 d => d Source #

class D1 d where Source #

Minimal complete definition

d1

Methods

d1 :: Prism' d () Source #

Instances

D1 Digit Source # 

Methods

d1 :: Prism' Digit () Source #

x1 :: D1 d => d Source #

class D2 d where Source #

Minimal complete definition

d2

Methods

d2 :: Prism' d () Source #

Instances

D2 Digit Source # 

Methods

d2 :: Prism' Digit () Source #

x2 :: D2 d => d Source #

class D3 d where Source #

Minimal complete definition

d3

Methods

d3 :: Prism' d () Source #

Instances

D3 Digit Source # 

Methods

d3 :: Prism' Digit () Source #

x3 :: D3 d => d Source #

class D4 d where Source #

Minimal complete definition

d4

Methods

d4 :: Prism' d () Source #

Instances

D4 Digit Source # 

Methods

d4 :: Prism' Digit () Source #

x4 :: D4 d => d Source #

class D5 d where Source #

Minimal complete definition

d5

Methods

d5 :: Prism' d () Source #

Instances

D5 Digit Source # 

Methods

d5 :: Prism' Digit () Source #

x5 :: D5 d => d Source #

class D6 d where Source #

Minimal complete definition

d6

Methods

d6 :: Prism' d () Source #

Instances

D6 Digit Source # 

Methods

d6 :: Prism' Digit () Source #

x6 :: D6 d => d Source #

class D7 d where Source #

Minimal complete definition

d7

Methods

d7 :: Prism' d () Source #

Instances

D7 Digit Source # 

Methods

d7 :: Prism' Digit () Source #

x7 :: D7 d => d Source #

class D8 d where Source #

Minimal complete definition

d8

Methods

d8 :: Prism' d () Source #

Instances

D8 Digit Source # 

Methods

d8 :: Prism' Digit () Source #

x8 :: D8 d => d Source #

class D9 d where Source #

Minimal complete definition

d9

Methods

d9 :: Prism' d () Source #

Instances

D9 Digit Source # 

Methods

d9 :: Prism' Digit () Source #

x9 :: D9 d => d Source #

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

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

data Digits Source #

Instances

Eq Digits Source # 

Methods

(==) :: Digits -> Digits -> Bool #

(/=) :: Digits -> Digits -> Bool #

Data Digits Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Digits -> c Digits #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Digits #

toConstr :: Digits -> Constr #

dataTypeOf :: Digits -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Digits) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Digits) #

gmapT :: (forall b. Data b => b -> b) -> Digits -> Digits #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Digits -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Digits -> r #

gmapQ :: (forall d. Data d => d -> u) -> Digits -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Digits -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Digits -> m Digits #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Digits -> m Digits #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Digits -> m Digits #

Ord Digits Source # 
Show Digits Source # 
Semigroup Digits Source # 
Monoid Digits Source # 
Ixed Digits Source # 
AsEmpty Digits Source # 

Methods

_Empty :: Prism' Digits () #

Plated Digits Source # 
Reversing Digits Source # 

Methods

reversing :: Digits -> Digits #

Cons Digits Digits Digit Digit Source # 
Snoc Digits Digits Digit Digit Source # 
Each Digits Digits Digit Digit Source # 
type Index Digits Source # 
type IxValue Digits Source # 

(/+/) :: 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]

(.*.) :: Digits -> Digits -> Digits Source #

>>> Digits [x2] .*. Digits [x1, x0]
Digits [2,0]
>>> Digits [x1, x2, x3] .*. Digits [x4, x5, x6]
Digits [5,6,0,8,8]

mantissa :: Floating a => Digits -> a Source #

>>> mantissa (Digits []) :: Double
0.0
mantissa (Digits [x0]) :: Double
  1. 0
>>> mantissa (Digits [x1]) :: Double
0.1
>>> mantissa (Digits [x1, x9]) :: Double
0.19