Re: [Haskell-cafe] efficient chop

2011-09-15 Thread Sean Leather
On Wed, Sep 14, 2011 at 17:31, Ivan Lazar Miljenovic wrote: On 15 September 2011 01:24, Sean Leather wrote: On Wed, Sep 14, 2011 at 05:03, Kazu Yamamoto wrote: I would like to have an efficient implementation of the chop function. [...] Are there any more efficient

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Daniel Gorín
On Sep 14, 2011, at 5:29 AM, Kazu Yamamoto (山本和彦) wrote: Hello, Of course, I use ByteString or Text for real programming. But I would like to know whether or not there are any efficient methods to remove a tail part of a list. --Kazu In that case, I would prefer this version, since it

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread 山本和彦
Hello, My friend reached the following version: chop :: String - String chop = foldr go [] where go x xs | isSpace x null xs = [] | otherwise= x:xs This version is faster than the reverse version in most cases. The point is checking isSpace first and falling into

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Roman Cheplyaka
* Kazu Yamamoto k...@iij.ad.jp [2011-09-14 15:59:05+0900] Hello, My friend reached the following version: chop :: String - String chop = foldr go [] where go x xs | isSpace x null xs = [] | otherwise= x:xs This version is faster than the reverse

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread 山本和彦
You can find the results of my friend: https://gist.github.com/1215660 Please ignore the Japanese text. Please read the code and the results. I'm not sure why you had the different result. --Kazu This was exactly my first attempt on rewriting your foldr version. Unfortunately, it

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Daniel Fischer
On Wednesday 14 September 2011, 09:17:16, Kazu Yamamoto wrote: You can find the results of my friend: https://gist.github.com/1215660 Please ignore the Japanese text. Please read the code and the results. I'm not sure why you had the different result. Input size. The lazy foldr

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Sean Leather
On Wed, Sep 14, 2011 at 05:03, Kazu Yamamoto wrote: I would like to have an efficient implementation of the chop function. [...] Are there any more efficient implementations of chop? Any suggestions? chop xs = go xs id where go _ = id go (c:cs) ss |

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Ivan Lazar Miljenovic
On 15 September 2011 01:24, Sean Leather leat...@cs.uu.nl wrote: On Wed, Sep 14, 2011 at 05:03, Kazu Yamamoto wrote: I would like to have an efficient implementation of the chop function. [...] Are there any more efficient implementations of chop? Any suggestions?   chop xs = go xs id  

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread Donn Cave
Quoth Ivan Lazar Miljenovic ivan.miljeno...@gmail.com, Why the extra case for go? The otherwise guard can be part of the second case... I noticed that myself, so I thought let's see if it's just a matter of style that comes out the same after compilation ... ... and after a few minutes

Re: [Haskell-cafe] efficient chop

2011-09-14 Thread wren ng thornton
On 9/13/11 11:03 PM, Kazu Yamamoto (山本和彦) wrote: Hello Cafe, I would like to have an efficient implementation of the chop function. As you guess, the chop function drops spaces in the tail of a list. chop foo bar baz - foo bar baz A naive implementation is as follows:

[Haskell-cafe] efficient chop

2011-09-13 Thread 山本和彦
Hello Cafe, I would like to have an efficient implementation of the chop function. As you guess, the chop function drops spaces in the tail of a list. chop foo bar baz -foo bar baz A naive implementation is as follows: chopReverse :: String - String chopReverse =

Re: [Haskell-cafe] efficient chop

2011-09-13 Thread Thomas DuBuisson
This was a recent question on StackOverflow: http://stackoverflow.com/questions/6270324/in-haskell-how-do-you-trim-whitespace-from-the-beginning-and-end-of-a-string/6270382#6270382 Where I started: If you have serious text processing needs then use the text package from hackage. And concluded:

Re: [Haskell-cafe] efficient chop

2011-09-13 Thread 山本和彦
Hello, Of course, I use ByteString or Text for real programming. But I would like to know whether or not there are any efficient methods to remove a tail part of a list. --Kazu From: Thomas DuBuisson thomas.dubuis...@gmail.com Subject: Re: [Haskell-cafe] efficient chop This was a recent

Re: [Haskell-cafe] efficient chop

2011-09-13 Thread Ivan Lazar Miljenovic
On 14 September 2011 13:29, Kazu Yamamoto k...@iij.ad.jp wrote: Hello, Of course, I use ByteString or Text for real programming. But I would like to know whether or not there are any efficient methods to remove a tail part of a list. I doubt it; lists aren't that great a data type if you