On Tue, 02 Mar 2004 16:59:48 -0800, Iavor S. Diatchki <[EMAIL PROTECTED]> wrote:
i'd like to suggest that the definition of "intersperse" from the List module be made more lazy.

Good thing, I think that library functions should always be as lazy as possible in their observeable interface (or well documented why they aren't)

intersperse             :: a -> [a] -> [a]
intersperse _   []      = []
intersperse sep (x:xs)  = x : rest
  where rest [] = []
        rest xs = sep : intersperse sep xs

I don't like the generic name "rest" so much, and the function is not as efficient as it could be due to too much matching -- what about:

intersperse            :: a -> [a] -> [a]
intersperse sep []     = []
intersperse sep (x:xs) = x : prefix sep xs

prefix            :: a -> [a] -> [a]
prefix sep []     = []
prefix sep (x:xs) = sep : x : prefix sep xs


-- Daan.

_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to