Expose internal Int in IDs and make the type an instance of Random (generating only positive IDs)
This commit is contained in:
parent
e0003c5906
commit
3440c84543
1 changed files with 12 additions and 5 deletions
|
@ -1,10 +1,17 @@
|
||||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||||
module Hanafuda.ID (
|
module Hanafuda.ID (
|
||||||
ID(..)
|
ID(..)
|
||||||
, getID
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
newtype ID a = ID Int deriving (Eq, Ord, Enum, Read, Show)
|
import System.Random (Random(..))
|
||||||
|
|
||||||
getID :: ID a -> String
|
newtype ID a = ID {
|
||||||
getID (ID n) = show n
|
getID :: Int
|
||||||
|
} deriving (Eq, Ord, Enum, Read, Show)
|
||||||
|
|
||||||
|
rIntToRID :: (Int, g) -> (ID a, g)
|
||||||
|
rIntToRID (someID, g) = (ID someID, g)
|
||||||
|
|
||||||
|
instance Random (ID a) where
|
||||||
|
random = rIntToRID . randomR (0, maxBound)
|
||||||
|
randomR (ID idA, ID idB) = rIntToRID . randomR (idA, idB)
|
||||||
|
|
Loading…
Reference in a new issue