Make lines stricter to fix a space leak

Daniel Fischer daniel.is.fischer at web.de
Mon Oct 4 15:05:08 EDT 2010


On Monday 04 October 2010 20:19:39, Daniel Fischer wrote:
>
> Yes, they are fragile.
> However, since (to my surprise) uncurry isn't available in Data.List,
> I've tried with a special function for uncurry (:),
>
> cons :: (a,[a]) -> [a]
> cons (x,xs) = x : xs
>
> vlines :: String -> [String]
> vlines "" = []
> vlines s  = cons $ case break (== '\n') s of
>                     (l, s') -> (l, case s' of
>                                     []    -> []
>                                     _:s'' -> vlines s'')
>
> , which gives slightly less fragile looking Core (

> --the second argument of (:) doesn't contain a reference to the first
> anymore).

Arrgh. And that is again as strict as the naked case, cons needs a lazy 
pattern, which means it gets the same core as uncurry (:).

Still, it doesn't leak on current GHCs, so for the time being, it's a fix 
(not on JHC though, that leaks with all implementations I tried).

If anybody can offer a more stable fix of the leak, I'd be happy.



More information about the Libraries mailing list