<html><head><base href="x-msg://250/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>data&nbsp;<span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; ">FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 | NoFigure</span></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deriving (Enum)</span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">randomFigure :: IO FigType</span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;">randomFigure = toEnum &lt;$&gt; randomRIO (1,11)</span></font></div><div><br></div><div>Bob</div><br><div><div>On 14 Mar 2010, at 10:57, Evgenij Merenkov wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">Hello.<br><br>I have the following data and it's constructors:<br><font face="Courier New"><br></font><font face="Courier New">FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 | NoFigure</font><br><br>I need to randomly return one of them in a function. The obvious solution to me, is simply using a random number generator and case statement, where each value generated is associated with each data constructor. Like this:<br><font face="Courier New"><br></font><font face="Courier New">import System.Random</font><font face="Courier New"><br></font><font face="Courier New"><br></font><font face="Courier New">randomFigType :: IO FigType</font><font face="Courier New"><br></font><font face="Courier New">randomFigure = do</font><font face="Courier New"><br></font><font face="Courier New">&nbsp; x &lt;- randomRIO (1::Int,11::Int)</font><font face="Courier New"><br></font><font face="Courier New">&nbsp; return $ case x of</font><font face="Courier New"><br></font><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 -&gt; TR1</font><font face="Courier New"><br></font><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 -&gt; TR2</font><font face="Courier New"><br></font><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 -&gt; TR3</font><br>e t.c.<br><br>But is there a more direct way to do this?<br><br><hr>Hotmail: Trusted email with Microsoft’s powerful SPAM protection.<span class="Apple-converted-space">&nbsp;</span><a href="https://signup.live.com/signup.aspx?id=60969" target="_new">Sign up now.</a><span class="Apple-converted-space">&nbsp;</span>_______________________________________________<br>Beginners mailing list<br><a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a><br></div></span></blockquote></div><br></body></html>