[Haskell-cafe] minor refactoring problem

Martin DeMello martindemello at gmail.com
Tue Nov 29 10:05:56 CET 2011


On Tue, Nov 29, 2011 at 12:55 AM, Stefan Holdermans
<stefan at vectorfabrics.com> wrote:
> Martin,
>
>> (The trick with `flip` is tempting, but again at the
>> cost of having to peer rather too closely at the implementation of
>> processFile when reading the code).
>
> That "trick" is of course completely orthogonal. One could just as well write:
>
>  processFile :: (String -> [a]) -> (a -> (String, String)) -> Editor -> String -> IO ()
>  processFile f g ed path = do
>    s <- readFile path
>    ps -> mapM (makePair . g) (f s)
>    es -> return $ V.fromList ps
>    writeIORef ed es
>
>  importFile = processFile lines (\x -> (x, ""))
>  loadFile   = processFile parseFile id

good point :) though i ended up writing a new function parseImport =
(map $ \x -> (x, "")) . lines, so that i could drop the second
argument and have everything look nice and neat.

martin



More information about the Haskell-Cafe mailing list