roc-id-0.2.0.0: library/ROC/ID/Digit.hs
{-# LANGUAGE DeriveGeneric #-}
module ROC.ID.Digit
( Digit (..)
, parseDigit
) where
import GHC.Generics
( Generic )
import ROC.ID.Utilities
-- | Represents a single decimal digit in the range 0 to 9.
--
data Digit
= D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
deriving (Bounded, Enum, Eq, Generic, Ord)
instance Show Digit where show = show . fromEnum
parseDigit :: Char -> Maybe Digit
parseDigit c = maybeRead [c] >>= maybeToEnum