{-# LANGUAGE Safe #-}
module Data.Char.Dice(
DieValue(I, II, III, IV, V, VI)
, toDieValue
, die
) where
import Data.Bits((.|.))
import Data.Char(chr)
import Data.Char.Core(UnicodeCharacter(toUnicodeChar, fromUnicodeChar, fromUnicodeChar'), UnicodeText, mapFromEnum, mapToEnum, mapToEnumSafe)
import Test.QuickCheck.Arbitrary(Arbitrary(arbitrary), arbitraryBoundedEnum)
_dieOffset :: Int
_dieOffset :: Int
_dieOffset = Int
0x2680
data DieValue
= I
| II
| III
| IV
| V
| VI
deriving (DieValue
DieValue -> DieValue -> Bounded DieValue
forall a. a -> a -> Bounded a
maxBound :: DieValue
$cmaxBound :: DieValue
minBound :: DieValue
$cminBound :: DieValue
Bounded, Int -> DieValue
DieValue -> Int
DieValue -> [DieValue]
DieValue -> DieValue
DieValue -> DieValue -> [DieValue]
DieValue -> DieValue -> DieValue -> [DieValue]
(DieValue -> DieValue)
-> (DieValue -> DieValue)
-> (Int -> DieValue)
-> (DieValue -> Int)
-> (DieValue -> [DieValue])
-> (DieValue -> DieValue -> [DieValue])
-> (DieValue -> DieValue -> [DieValue])
-> (DieValue -> DieValue -> DieValue -> [DieValue])
-> Enum 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
(DieValue -> DieValue -> Bool)
-> (DieValue -> DieValue -> Bool) -> Eq DieValue
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, Eq DieValue
Eq DieValue
-> (DieValue -> DieValue -> Ordering)
-> (DieValue -> DieValue -> Bool)
-> (DieValue -> DieValue -> Bool)
-> (DieValue -> DieValue -> Bool)
-> (DieValue -> DieValue -> Bool)
-> (DieValue -> DieValue -> DieValue)
-> (DieValue -> DieValue -> DieValue)
-> Ord 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
$cp1Ord :: Eq DieValue
Ord, ReadPrec [DieValue]
ReadPrec DieValue
Int -> ReadS DieValue
ReadS [DieValue]
(Int -> ReadS DieValue)
-> ReadS [DieValue]
-> ReadPrec DieValue
-> ReadPrec [DieValue]
-> Read 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
(Int -> DieValue -> ShowS)
-> (DieValue -> String) -> ([DieValue] -> ShowS) -> Show DieValue
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)
toDieValue :: Integral i
=> i
-> Maybe DieValue
toDieValue :: i -> Maybe DieValue
toDieValue i
i
| i
i i -> i -> Bool
forall a. Ord a => a -> a -> Bool
> i
0 Bool -> Bool -> Bool
&& i
i i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
6 = DieValue -> Maybe DieValue
forall a. a -> Maybe a
Just (Int -> DieValue
forall a. Enum a => Int -> a
toEnum (i -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral i
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
| Bool
otherwise = Maybe DieValue
forall a. Maybe a
Nothing
instance Arbitrary DieValue where
arbitrary :: Gen DieValue
arbitrary = Gen DieValue
forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum
die
:: DieValue
-> Char
die :: DieValue -> Char
die = Int -> Char
chr (Int -> Char) -> (DieValue -> Int) -> DieValue -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int
_dieOffset Int -> Int -> Int
forall a. Bits a => a -> a -> a
.|.) (Int -> Int) -> (DieValue -> Int) -> DieValue -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DieValue -> Int
forall a. Enum a => a -> Int
fromEnum
instance UnicodeCharacter DieValue where
toUnicodeChar :: DieValue -> Char
toUnicodeChar = Int -> DieValue -> Char
forall a. Enum a => Int -> a -> Char
mapFromEnum Int
_dieOffset
fromUnicodeChar :: Char -> Maybe DieValue
fromUnicodeChar = Int -> Char -> Maybe DieValue
forall a. (Bounded a, Enum a) => Int -> Char -> Maybe a
mapToEnumSafe Int
_dieOffset
fromUnicodeChar' :: Char -> DieValue
fromUnicodeChar' = Int -> Char -> DieValue
forall a. Enum a => Int -> Char -> a
mapToEnum Int
_dieOffset
instance UnicodeText DieValue