[Haskell-cafe] Printing a random list

Bryan Catanzaro catanzar at EECS.Berkeley.EDU
Sun Jun 8 19:28:49 EDT 2008

I'm just starting out with Haskell, and I could use some help.  I'm  
trying to create a random list and print it out, which seems simple  
enough, but has been giving me problems.  Here's what I have:

module Main
       import IO
       import Random

       randomList :: Random a => a -> a-> [IO a]
       randomList lbound ubound = randomRIO(lbound, ubound) :  
randomList lbound ubound

       main = do
         myRandomList <- sequence(randomList(0::Int 255))
         putStrLn(show(take(10 myRandomList)))


So, I have tried to make a randomList action which defines an infinite  
random list, bounded by lbound and ubound.  It seems that to print  
this, I need to convert between randomList, which is of type [IO a] to  
something like IO [a], which is what sequence should do for me.  Then  
I just want to print out the first 10 elements.

I'm currently getting the error "Only unit numeric type pattern is  
valid", pointing to 0::Int 255 in the code.  I'm not sure what this  

I'm sure I'm looking at this the wrong way, since I'm new to Haskell  
and haven't quite wrapped my head around it yet.  Maybe you can fix  
the problem by showing me a more Haskell approach to creating a random  
list and printing it...  =)


- bryan catanzaro

More information about the Haskell-Cafe mailing list