[EMAIL PROTECTED] wrote:
> 
> Today, I reviewed a function I wrote a few months ago.  The function,
> dropTrailNulls, takes a list of lists and drops trailing null lists.  For
> instance:
> 
> *Main> dropTrailNulls [[1],[2,3],[],[]]
> [[1],[2,3]]

dropTrailNulls = foldr dtn []
  where
    dtn [] [] = []
    dtn  x xs = x:xs
    
 
> dropTrailNulls list = reverse (dropWhile null (reverse list))

As the other responses said, this is needlessly strict.  Work on
deforesting reverse exists, but you can't count on it happenig.


> is there a more efficient idiom for addressing these problems?

Well, there's always the basic fold.  I'm not sure there's any lesson to
be learnt here other than "fold is your friend".


Udo.
-- 
F:      Was ist ansteckend und kommutiert?
A:      Eine Abelsche Grippe.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to