{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeApplications #-}
module Data.Char.Dice
(
DieValue (I, II, III, IV, V, VI),
toDieValue,
die,
)
where
import Control.DeepSeq (NFData)
import Data.Bits ((.|.))
import Data.Char (chr)
import Data.Char.Core (UnicodeCharacter (fromUnicodeChar, fromUnicodeChar', isInCharRange, toUnicodeChar), UnicodeText (isInTextRange), generateIsInTextRange', mapFromEnum, mapToEnum, mapToEnumSafe)
import Data.Data (Data)
import Data.Hashable (Hashable)
import GHC.Generics (Generic)
import Test.QuickCheck.Arbitrary (Arbitrary (arbitrary), arbitraryBoundedEnum)
_dieOffset :: Int
_dieOffset :: Int
_dieOffset = Int
0x2680
data DieValue
=
I
|
II
|
III
|
IV
|
V
|
VI
deriving (DieValue
forall a. a -> a -> Bounded a
maxBound :: DieValue
$cmaxBound :: DieValue
minBound :: DieValue
$cminBound :: DieValue
Bounded, Typeable DieValue
DieValue -> DataType
DieValue -> Constr
(forall b. Data b => b -> b) -> DieValue -> DieValue
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> DieValue -> u
forall u. (forall d. Data d => d -> u) -> DieValue -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DieValue -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DieValue -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DieValue
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DieValue -> c DieValue
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DieValue)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DieValue)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DieValue -> m DieValue
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DieValue -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DieValue -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> DieValue -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DieValue -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DieValue -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DieValue -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DieValue -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DieValue -> r
gmapT :: (forall b. Data b => b -> b) -> DieValue -> DieValue
$cgmapT :: (forall b. Data b => b -> b) -> DieValue -> DieValue
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DieValue)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DieValue)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DieValue)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DieValue)
dataTypeOf :: DieValue -> DataType
$cdataTypeOf :: DieValue -> DataType
toConstr :: DieValue -> Constr
$ctoConstr :: DieValue -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DieValue
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DieValue
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DieValue -> c DieValue
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DieValue -> c DieValue
Data, Int -> DieValue
DieValue -> Int
DieValue -> [DieValue]
DieValue -> DieValue
DieValue -> DieValue -> [DieValue]
DieValue -> DieValue -> DieValue -> [DieValue]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: DieValue -> DieValue -> DieValue -> [DieValue]
$cenumFromThenTo :: DieValue -> DieValue -> DieValue -> [DieValue]
enumFromTo :: DieValue -> DieValue -> [DieValue]
$cenumFromTo :: DieValue -> DieValue -> [DieValue]
enumFromThen :: DieValue -> DieValue -> [DieValue]
$cenumFromThen :: DieValue -> DieValue -> [DieValue]
enumFrom :: DieValue -> [DieValue]
$cenumFrom :: DieValue -> [DieValue]
fromEnum :: DieValue -> Int
$cfromEnum :: DieValue -> Int
toEnum :: Int -> DieValue
$ctoEnum :: Int -> DieValue
pred :: DieValue -> DieValue
$cpred :: DieValue -> DieValue
succ :: DieValue -> DieValue
$csucc :: DieValue -> DieValue
Enum, DieValue -> DieValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DieValue -> DieValue -> Bool
$c/= :: DieValue -> DieValue -> Bool
== :: DieValue -> DieValue -> Bool
$c== :: DieValue -> DieValue -> Bool
Eq, forall x. Rep DieValue x -> DieValue
forall x. DieValue -> Rep DieValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DieValue x -> DieValue
$cfrom :: forall x. DieValue -> Rep DieValue x
Generic, Eq DieValue
DieValue -> DieValue -> Bool
DieValue -> DieValue -> Ordering
DieValue -> DieValue -> DieValue
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: DieValue -> DieValue -> DieValue
$cmin :: DieValue -> DieValue -> DieValue
max :: DieValue -> DieValue -> DieValue
$cmax :: DieValue -> DieValue -> DieValue
>= :: DieValue -> DieValue -> Bool
$c>= :: DieValue -> DieValue -> Bool
> :: DieValue -> DieValue -> Bool
$c> :: DieValue -> DieValue -> Bool
<= :: DieValue -> DieValue -> Bool
$c<= :: DieValue -> DieValue -> Bool
< :: DieValue -> DieValue -> Bool
$c< :: DieValue -> DieValue -> Bool
compare :: DieValue -> DieValue -> Ordering
$ccompare :: DieValue -> DieValue -> Ordering
Ord, ReadPrec [DieValue]
ReadPrec DieValue
Int -> ReadS DieValue
ReadS [DieValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DieValue]
$creadListPrec :: ReadPrec [DieValue]
readPrec :: ReadPrec DieValue
$creadPrec :: ReadPrec DieValue
readList :: ReadS [DieValue]
$creadList :: ReadS [DieValue]
readsPrec :: Int -> ReadS DieValue
$creadsPrec :: Int -> ReadS DieValue
Read, Int -> DieValue -> ShowS
[DieValue] -> ShowS
DieValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DieValue] -> ShowS
$cshowList :: [DieValue] -> ShowS
show :: DieValue -> String
$cshow :: DieValue -> String
showsPrec :: Int -> DieValue -> ShowS
$cshowsPrec :: Int -> DieValue -> ShowS
Show)
instance Hashable DieValue
instance NFData DieValue
toDieValue ::
Integral i =>
i ->
Maybe DieValue
toDieValue :: forall i. Integral i => i -> Maybe DieValue
toDieValue i
i
| i
i forall a. Ord a => a -> a -> Bool
> i
0 Bool -> Bool -> Bool
&& i
i forall a. Ord a => a -> a -> Bool
<= i
6 = forall a. a -> Maybe a
Just (forall a. Enum a => Int -> a
toEnum (forall a b. (Integral a, Num b) => a -> b
fromIntegral i
i forall a. Num a => a -> a -> a
- Int
1))
| Bool
otherwise = forall a. Maybe a
Nothing
instance Arbitrary DieValue where
arbitrary :: Gen DieValue
arbitrary = forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum
die ::
DieValue ->
Char
die :: DieValue -> Char
die = Int -> Char
chr forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int
_dieOffset forall a. Bits a => a -> a -> a
.|.) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => a -> Int
fromEnum
instance UnicodeCharacter DieValue where
toUnicodeChar :: DieValue -> Char
toUnicodeChar = forall a. Enum a => Int -> a -> Char
mapFromEnum Int
_dieOffset
fromUnicodeChar :: Char -> Maybe DieValue
fromUnicodeChar = forall a. (Bounded a, Enum a) => Int -> Char -> Maybe a
mapToEnumSafe Int
_dieOffset
fromUnicodeChar' :: Char -> DieValue
fromUnicodeChar' = forall a. Enum a => Int -> Char -> a
mapToEnum Int
_dieOffset
isInCharRange :: Char -> Bool
isInCharRange Char
c = Char
'\x2680' forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c forall a. Ord a => a -> a -> Bool
<= Char
'\x2685'
instance UnicodeText DieValue where
isInTextRange :: Text -> Bool
isInTextRange = forall a. UnicodeCharacter a => Text -> Bool
generateIsInTextRange' @DieValue