<div dir="ltr">I&#39;ve butted into this problem multiple times, so I thought it&#39;s finally time to get a good solution. I don&#39;t even have the terminology to describe the issue, so I&#39;ll just post the code I&#39;m annoyed with and hope someone understands what I mean.<br>
<br><div style="margin-left: 40px;">import Control.Monad.Random<br>import System.Random<br><br>data Marital = Single | Married | Divorced<br>    deriving (Enum, Bounded, Show)<br><br>randomEnum :: (Enum a, Bounded a, RandomGen g) =&gt; Rand g a<br>
randomEnum = do<br>    let minb = minBound<br>        maxb = maxBound<br>    randVal &lt;- getRandomR (fromEnum minb, fromEnum maxb)<br>    return $ head [toEnum randVal, minb, maxb] -- if I do the obvious thing (return $ toEnum randVal) I get funny errors<br>
<br>main = do<br>    stdGen &lt;- newStdGen<br>    let marital = evalRand randomEnum stdGen :: Marital<br>    putStrLn $ &quot;Random marital status: &quot; ++ show marital<br><br></div>Any help is appreciated. Thanks!<br>
Michael<br></div>