> Yes, break is very expensive due to its pairing up of results 
> for every
> character consumed.  You didn't mention the accumulating 
> parameter version:
> 
> lines :: String -> [String]
> lines s = lines' s ""
>   where
>   lines' []       acc = [acc]
>   lines' ('\n':s) acc = reverse acc : lines' s ""
>   lines' (c:s)    acc = lines' s (c:acc)

correction: that should really be

> lines :: String -> [String]
> lines s = lines' s ""
>   where
--->lines' []       ""  = []
>   lines' []       acc = [acc]
>   lines' ('\n':s) acc = reverse acc : lines' s ""
>   lines' (c:s)    acc = lines' s (c:acc)

Simon

Reply via email to