<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 1, 2015 at 5:32 PM, David McBride <span dir="ltr"><<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>mkStdGen only accepts Ints as seeds. But your random function, as you typed it, can return any type of random. You either have to restrict your random function to returning ints, like so:<br><br>myrandoms :: (RandomGen g) => g -> [Int]<br>myrandoms gen = let (value, newGen) = random gen in value:myrandoms (mkStdGen value)<br></div></div></div></blockquote><div><br><b><br></b></div><div><b>Is there any good reason we're not using newGen for its intended purpose here and instead weakening our randomness, maybe extremely (imagine if a list a Bool is asked for...) ???<br></b><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><br></div>Or you have to find a way to convert any Random a into an Int (not possible), or put another constraint on it, such that you can return all the types you might want that you have the ability to turn into ints, for example:<br><br>myrandoms :: (RandomGen g, Random a, Intable a) => g -> [a]<br>myrandoms gen = let (value, newGen) = random gen in value:myrandoms (mkStdGen $ convertToInt value)<br><br>class Intable a where<br> convertToInt :: a -> Int<br><br>instance Intable Int where convertToInt = id<br>instance Intable Integer where convertToInt = fromIntegral<br>instance Intable Char where convertToInt s = undefined -- something<br><br></div>Which is obviously tedious, but may be worthwhile depending on your application.<br></div>
<br></blockquote></div><br></div><div class="gmail_extra">If this was really the way Shishir wanted to go, I would suggest simply reusing the Enum typeclass rather than creating a new Intable typeclass, since : fromEnum :: (Enum a) => a -> Int<br><br></div><div class="gmail_extra">Still a very bad and puzzling idea by the way...<br><br>-- <br></div><div class="gmail_extra">Jedaï<br></div></div>