Re: [Haskell-cafe] Combine list of sorted lists

2006-12-29 Thread Quan Ta
On 12/29/06, Neil Mitchell <[EMAIL PROTECTED]> wrote: map (:[]), :[] takes a single element and puts it into a list. Some people refer to this as "box" The final f3 clause can be made a bit neater: > f3 la@(a:as) lb@(b:bs) | sum a <= sum b = a : f3 as lb |

Re: [Haskell-cafe] Combine list of sorted lists

2006-12-29 Thread Quan Ta
On 12/29/06, Neil Mitchell <[EMAIL PROTECTED]> wrote: Hi > f1 :: [Int] -> [[Int]] >f1 [] = [] > f1 (a:as) = [a] : f1 as f1 is simply a map > f3 la lb = let a = head la > b = head lb > in if sum a <= sum b then >

[Haskell-cafe] Combine list of sorted lists

2006-12-28 Thread Quan Ta
Hi all, I have this function which combines (zip) list of sorted lists into a sorted list (sorted by sum). The function works with infinite list and seems to give correct result. But after I see the code for the Hamming sequence from the Wiki, I wonder if it can be written better, or more clear

Re: [Haskell-cafe] Mixing IO and STM

2005-12-29 Thread Quan Ta
On 12/29/05, Brian Sniffen <[EMAIL PROTECTED]> wrote: > test_Cubby =>   do> tv <- newTVar 0You've almost got it!  But "newTVar 0" has type STM Tvar, and you'retrying to use it in the IO monad.  So just say "tv <- atomically (newTVar 0)" and you're set.  Do notice that you'll see output likethis

[Haskell-cafe] Mixing IO and STM

2005-12-29 Thread Quan Ta
Hello folks, Newbie question: how can I do something like the following? mixing IO and STM.   module Test whereimport System.Random import Control.Concurrentimport Control.Concurrent.STM test_Cubby =  do tv <- newTVar 0 forkIO (producer tv) >> (consumer tv)  where producer tv = do r <-