> 
> Then split it up like you'd do in an OO language. I think, FP also
> is good for writing small functions that do one thing well, and then
> composing them in various ways (as you see, composing functions (and
> perhaps also values) in Haskell is possible in very many various ways :-) ).
> 
> In the running example, I could imagine those auxiliary functions:
> 
> splitFilterMap unSplitFn afterMap filterPredicate beforeMap splitFn =
>   unSplitFn . map afterMap . filter filterPredicate . map beforeMap . splitFn
> -- perhaps make that more generic by using fmap and mfilter
> -- with this definition (that seems to be something generic enough for
> -- the Monad library...):
> -- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
> -- mfilter fn m = m >>= (\a -> if fn a then mzero else return a)

sorry this looks morre terrible to me than all solutions before, IMO way
to much parameters and the names don't give me a good hint of what e.g
beforeMap does. 


> 
> splitFilter unSplitFn filterPred splitFn =
>   splitFilterMap unSplitFn id filterPred id splitFn
> 
> lenGt limit list = length list > limit
> 
> processFile limit = splitFilter unlines (lenGt limit) lines
> -- for the unnumbered version
>   OR

I think s.th in that directin is somewhar what I like more
> 
> numberElems = zip [1..]
> 
> number2str (nr,l) = show nr ++ '\t' : l
I would not call it number2 s.th it does not expplain to me that
something is printed so maybe 
print_number_str_pair or the like would be fine for me
> 
> processFile limit = splitFilterMap unlines number2str (lenGt limit . snd)
>   id (numberElems . lines)

I don't think that I could work with splitFilterMap. Nevertheless is
shows me all way lead to ROME ;-)

I re-wrote that stuff in Python and I've to admit it's way easier to
understand for me (not even talking of writing). But I think it was  a
good example to learn how FP-trained would do it. It's a long long way
to go;-)


Regards
Friedrich


Reply via email to