[Haskell-cafe] Re: foreach
apfelmus at quantentunnel.de
apfelmus at quantentunnel.de
Fri Sep 15 05:00:47 EDT 2006
Bulat Ziganshin wrote:
> because REAL code is somewhat larger than examples. try to rewrite the
> following:
>
> directory_blocks <- (`mapM` splitBy (opt_group_dir command) files_to_archive)
> ( \filesInOneDirectory -> do
> datablocks <- (`mapM` splitToSolidBlocks filesInOneDirectory)
> ( \filesInOneDataBlock -> do
> [...]
This particular snippet contains too many undefined identifiers to be
rewritten effectively, but I'm very sure that the whole program can be
restructured to great effect.
Maybe by designing a "binary-block"-combinator language which calculates
padding bytes and length headers automatically and fiddles out
scheduling for fast writing to a pipe, something like that. Eventually,
a binary parser combinator library which can read single bit flags and
things is a must here. It may even be possible to combine the two
providing a bijection between abstract file tree, "tar"-ed blocks and
compressed binary file. Separate your concerns, ban IO as much as
possible and any function that takes more than 15 lines is a wart.
I admit that real world applications are not a good exercise to practice
functional programming, but once acquired, advanced functional tactics
prove very powerful. An example might be WASH/CGI which successfully
abstracts session state over HTTP, a problem where Perl-Scripts are
doomed and all kind of imperative buzz like JavaBeans and so on have
been invented but somewhat fail to solve it for non-trivial cases.
Regards,
afpelmus
More information about the Haskell-Cafe
mailing list