
On Wed, 2011-09-28 at 12:58 +0200, Joachim Breitner wrote:
Hi,
Am Mittwoch, den 28.09.2011, 19:14 +0900 schrieb Kazu Yamamoto:
If you still want to use this to teach students (maybe because you're building them up to "but in general you shouldn't do this") then provide this function for their use elsewhere (either as something to copy/paste, or an auxiliary library for your class). But I don't think it belongs in Data.List.
So, what about 'reverse'?
Both 'reverse' and 'tailDropWhile' are inefficient. Data.List has 'reverse'. Why not 'tailDropWhile'?
also, it’s performance is not too bad, and definitely not as bad as reverse: If tailDropWhile is implemented in a way that allows list fusion (should be possible, I think), and I know that the suffix is not large (e.g. stripping at most trailing "\n"), then tailDropWhile should be ok to use.
Greetings, Joachim
Using stream-fusion package types [I know too little to know how the ghc uses stream-fusion - but I think it shows it is possible to implement this] (not tested): tailDropWhile :: (a -> Bool) -> Stream a -> Stream a tailDropWhile f (Stream next0 s01) = Stream next (Right s0, []) where next (Right s1, vs) = case next0 s1 of Done -> Done Skip s2 -> Skip (Right s2, vs) Yield v s2 | f v -> Skip (Right s2, v:vs) | otherwise -> case vs of [] -> Yield v (Right s2, []) (x:xs) -> Yield x (Left (s2, v), xs) next (Left (s1, v), []) = Yield v (Right s2) next (Left (s1, v), (x:xs)) = Yield v (Left (s1, v), xs) Regards