Hello!

On Fri, Jun 04, 1999 at 12:18:31PM +0200, Friedrich Dominicus wrote:

> [...]

> > splitFilterMap unSplitFn afterMap filterPredicate beforeMap splitFn =
> >   unSplitFn . map afterMap . filter filterPredicate . map beforeMap . splitFn
> [...]

> 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. 

That's a HOF that first splits something up to a list using splitFn
(or with the generalization I mentioned, to a monad), then maps a
function over that list (namely beforeMap, because it's mapped
*before* the filter), filters something out (using the filterPredicate),
then again maps a function (namely afterMap, because it's mapped
*after* the filter), then somehow joins the list (or monad), using
unSplitFn.

> > splitFilter unSplitFn filterPred splitFn =
> >   splitFilterMap unSplitFn id filterPred id splitFn

That's just a specialization if there's no need for mapping a function
over the list before or after the filtering.

> > lenGt limit list = length list > limit

That's used as filter predicate.

> > 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

But the function doesn't print either. It converts to a string.
Therefore 2str. You could call it
  numberStrPair2String
more accurately.

> > 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 ;-)

Hmmm. I think using higher order functions to encapsulate programming
structures (i.e. function concatenations, applications, etc.) is one
thing that makes up functional programming.

Just consider standard combinators like
  map, filter, foldl, foldr, sequence (Monads ahead :-) ), ...

> 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;-)

Did you use the more functional parts of Python there? map? filter? :-)

> Regards
> Friedrich

Regards, Hannah.


Reply via email to