> Simon Marlow wrote:
> 
>  | 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)
>  | 
>  | This one is more than twice as fast as the foldr
>  | version, despite the fact that it needs to reverse the
>  | accumulating parameter for each line.
> 
> Unfortunately, it is less lazy too, so it will blow out of
> heapspace on very long lines.

Yes, so it is.  But in fact, so is Wolfram's foldr version.

        head (head (lines ('x':error "urk!")))

should yield 'x' according to the report definition.

Simon

Reply via email to