On Wed, 8 Mar 2006 [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]]
http://www.haskell.org/pipermail/libraries
Hello Jeff,
Wednesday, March 8, 2006, 8:08:57 PM, you wrote:
>
dropTrailNulls list = reverse (dropWhile null (reverse list))
dropTrailNulls [] = []
dropTrailNulls ([]:xs) = case dropTrailNulls xs of
[] -> []
list -> []:list
drop
[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 [] []
On Mar 8, 2006, at 12:08 PM, [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]] My original implementation was terribl
> dropTrailNulls list = reverse (dropWhile null (reverse list))
Or more succinctly:
dropTrailNulls = reverse . dropWhile null . reverse
> Or, is there a more efficient idiom for addressing these problems?
The "bad thing" about this definition is that it is tail strict. Consider
["hello","every
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]]
My original implementation was terrible.
It was recursive, overly bulky, and difficult to