On Jul 25, 2015, at 10:43 AM, Nicholas Ingolia <n...@ingolia.org> wrote: > > I would suggest opening all files at the beginning. Generate all k-mers, > open a file for each, and make a HashMap from k-mer to file handle. When > you're done, run through the HashMap to close all file handles.
I really like this idea and feel I'm close to having something that works. Here's a bit: main = do reads <- readFasta "test.fa" let kmers = concatMap (findKmers 20 . toString . seqdata) reads let allMers = replicateM 5 "ACTG" let fileHandles = Map.fromList $ map (\x -> (x, openFile ("out/" ++ x) WriteMode)) allMers mapM_ (printMer fileHandles) kmers mapM_ hClose $ Map.elems fileHandles Here "fileHandles" type is: fileHandles :: Map.Map [Char] (IO Handle) But it would be much easier if the elems were just Handle's. Is there a way to do this? I tried this: let fileHandles = Map.fromList $ map (\x -> do h <- openFile ("out/" ++ x) WriteMode (x, h)) allMers I'm still really hung up on the whole IO monad thing. Ken