
29 Nov
2011
29 Nov
'11
3:16 a.m.
I have the following functions: makePair :: (String, String) -> IO PairBox parseFile :: String -> [(String, String)] importFile :: Editor -> String -> IO () importFile ed path = do s <- readFile path ps <- mapM (\x -> makePair (x, "")) (lines s) es <- return $ V.fromList ps writeIORef ed es loadFile :: Editor -> String -> IO () loadFile ed path = do s <- readFile path ps <- mapM makePair (parseFile s) es <- return $ V.fromList ps writeIORef ed es The problem is that loadFile and importFile are so similar it seems a shame not to combine them somehow, but anything I can think of doing leaves the code looking more rather than less messy. Any nice ideas? martin