Re: lines --- to derive, or not to derive ;-)

2000-05-11 Thread Wolfram Kahl
Simon Marlow writes: You didn't mention the accumulating parameter version: [[[with correction pointed out by Koen Claessen:]]] lines :: String - [String] lines s = lines' s "" where lines' [] acc = [reverse acc] lines' ('\n':s) acc = reverse acc : lines' s "" lines'

RE: lines --- to derive, or not to derive ;-)

2000-05-10 Thread Simon Marlow
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 |

Re: lines --- to derive, or not to derive ;-)

2000-05-10 Thread Wolfram Kahl
Shin-Cheng Mu [EMAIL PROTECTED] is puzzled why the derived foldr version of lines is significantly faster than the prelude version, which he recognises as an unfold: I am curious why the Prelude version is less efficient than the your fold version? It seems to me the fold version construct

RE: lines --- to derive, or not to derive ;-)

2000-05-10 Thread Simon Marlow
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

RE: lines --- to derive, or not to derive ;-)

2000-05-10 Thread Koen Claessen
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,

Re: lines --- to derive, or not to derive ;-)

2000-05-07 Thread Shin-Cheng Mu
Hi, Is there an explanation to this phenom Wolfram Kahl wrote: To my surprise, the prelude definition of lines: lines :: String - [String] lines "" = [] lines s = let (l, s') = break (== '\n') s in l : case s' of [] - []