Re: [Haskell-cafe] How to split this string.

2012-01-06 Thread Steve Horne
On 06/01/2012 10:39, Jon Fairbairn wrote: groupBy is currently implemented using span. It strikes me that we ought to specify some properties for what we want. Start by defining: pairwiseInOrderBy p l = all (uncurry p) (l `zip` drop 1 l) giving all (pairwiseInOrderBy p) (groupCut p l) and we wo

Re: [Haskell-cafe] How to split this string.

2012-01-06 Thread Jon Fairbairn
Steve Horne writes: > On 05/01/2012 11:09, Brandon Allbery wrote: >> On Thu, Jan 5, 2012 at 05:57, Steve Horne >> > > wrote: >> >> -- groupCut - Similar to groupBy, but where groupBy assumes an >> equivalence relation, >> -- groupCut takes a fun

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Christian Maeder
Am 05.01.2012 13:04, schrieb Steve Horne: [...] I was going to accuse you of cheating - who says there's a spare value to use? - but you seem to be using Maybe, so well played. You're also using unfoldr, which I really must play with a bit - I don't really have a feel for how unfolding works AT

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Steve Horne
On 05/01/2012 11:55, Christian Maeder wrote: Am 05.01.2012 11:57, schrieb Steve Horne: [...] groupCut :: (x -> x -> Bool) -> [x] -> [[x]] [...] How about a break function that respects an escape character (1. arg) (and drops the delimiter - 2. arg) and use this function for unfolding? Intere

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Christian Maeder
Am 05.01.2012 11:57, schrieb Steve Horne: [...] groupCut :: (x -> x -> Bool) -> [x] -> [[x]] [...] How about a break function that respects an escape character (1. arg) (and drops the delimiter - 2. arg) and use this function for unfolding? import Data.List break' :: (a -> Bool) -> (a -> Bo

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Steve Horne
On 05/01/2012 11:09, Brandon Allbery wrote: On Thu, Jan 5, 2012 at 05:57, Steve Horne > wrote: -- groupCut - Similar to groupBy, but where groupBy assumes an equivalence relation, -- groupCut takes a function that indicates where to cut. The

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Brandon Allbery
On Thu, Jan 5, 2012 at 05:57, Steve Horne wrote: > -- groupCut - Similar to groupBy, but where groupBy assumes an > equivalence relation, > -- groupCut takes a function that indicates where to cut. The two > parameters to this > -- function are always adjacent items from the list, and if the

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Steve Horne
On 05/01/2012 10:02, Jon Fairbairn wrote: Steve Horne writes: Personally, I think this is a tad disappointing. Given that groupBy cannot check or enforce that it's test respects equivalence classes, it should ideally give results that make as much sense as possible either way. That said, even

Re: [Haskell-cafe] How to split this string.

2012-01-05 Thread Jon Fairbairn
Steve Horne writes: > On 02/01/2012 11:12, Jon Fairbairn wrote: >> max writes: >> >>> I want to write a function whose behavior is as follows: >>> >>> foo "string1\nstring2\r\nstring3\nstring4" = ["string1", >>> "string2\r\nstring3", "string4"] >>> >>> Note the sequence "\r\n", which is ignored.

Re: [Haskell-cafe] How to split this string.

2012-01-04 Thread AUGER Cédric
Le Wed, 04 Jan 2012 17:49:15 +, Steve Horne a écrit : > On 04/01/2012 16:47, Steve Horne wrote: > > > > (a == a) > > reflexivity : (a == b) => (b == a) > > transitivity : (a == b) && (b == c) => (a == c) > > > Oops - that's... > > reflexivity : (a == a) > symmetry : (a == b) => (b ==

Re: [Haskell-cafe] How to split this string.

2012-01-04 Thread Christian Maeder
Am 04.01.2012 17:47, schrieb Steve Horne: On 02/01/2012 11:12, Jon Fairbairn wrote: max writes: I want to write a function whose behavior is as follows: foo "string1\nstring2\r\nstring3\nstring4" = ["string1", "string2\r\nstring3", "string4"] Note the sequence "\r\n", which is ignored. How c

Re: [Haskell-cafe] How to split this string.

2012-01-04 Thread Steve Horne
On 04/01/2012 16:47, Steve Horne wrote: (a == a) reflexivity : (a == b) => (b == a) transitivity : (a == b) && (b == c) => (a == c) Oops - that's... reflexivity : (a == a) symmetry : (a == b) => (b == a) transitivity : (a == b) && (b == c) => (a == c) An equivalence relation is a rela

Re: [Haskell-cafe] How to split this string.

2012-01-04 Thread Steve Horne
On 02/01/2012 11:12, Jon Fairbairn wrote: max writes: I want to write a function whose behavior is as follows: foo "string1\nstring2\r\nstring3\nstring4" = ["string1", "string2\r\nstring3", "string4"] Note the sequence "\r\n", which is ignored. How can I do this? cabal install split then d

Re: [Haskell-cafe] How to split this string.

2012-01-03 Thread Jonathan Frywater
If you're interested in learning parsec, RWH covered this topic in depth in Chapter 16, Choices and Errors: http://book.realworldhaskell.org/read/using-parsec.html. On Mon, Jan 2, 2012 at 3:44 AM, max wrote: > I want to write a function whose behavior is as follows: > > foo "string1\nstring2\r\n

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Markus Läll
String is really for small strings. Text is more efficent and also has more functionality, including most, if not all, of the functions defined for String. On Mon, Jan 2, 2012 at 3:12 PM, Anupam Jain wrote: > On Mon, Jan 2, 2012 at 5:52 PM, Felipe Almeida Lessa > wrote: >> On Mon, Jan 2, 2012 at

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Anupam Jain
On Mon, Jan 2, 2012 at 5:52 PM, Felipe Almeida Lessa wrote: > On Mon, Jan 2, 2012 at 10:12 AM, max wrote: >> This is the simplest solution of the proposed, in my opinion. Thank you >> very much. > > Better yet, don't use String and use Text.  Then you just need > T.splitOn "\r\n" [1]. That is ac

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Felipe Almeida Lessa
On Mon, Jan 2, 2012 at 10:12 AM, max wrote: > This is the simplest solution of the proposed, in my opinion. Thank you > very much. Better yet, don't use String and use Text. Then you just need T.splitOn "\r\n" [1]. Cheers, [1] http://hackage.haskell.org/packages/archive/text/0.11.1.12/doc/htm

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread max
В Mon, 02 Jan 2012 11:12:49 + Jon Fairbairn пишет: > max writes: > > > I want to write a function whose behavior is as follows: > > > > foo "string1\nstring2\r\nstring3\nstring4" = ["string1", > > "string2\r\nstring3", "string4"] > > > > Note the sequence "\r\n", which is ignored. How can I

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread emacsray
On Mon, Jan 02, 2012 at 12:44:23PM +0300, max wrote: > I want to write a function whose behavior is as follows: > > foo "string1\nstring2\r\nstring3\nstring4" = ["string1", > "string2\r\nstring3", "string4"] > > Note the sequence "\r\n", which is ignored. How can I do this? > >

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Jon Fairbairn
max writes: > I want to write a function whose behavior is as follows: > > foo "string1\nstring2\r\nstring3\nstring4" = ["string1", > "string2\r\nstring3", "string4"] > > Note the sequence "\r\n", which is ignored. How can I do this? cabal install split then do something like import Data.Li

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Yves Parès
Okay, so it doesn't handle different line-endings. I have a more general solution (statefulSplit) http://hpaste.org/55980 I cannot test it as I don't have an interpreter at hand, but if someone has, I'd be glad to have comments. (It might be more readable by using the State monad) 2012/1/2 max

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread emacsray
On Mon, Jan 02, 2012 at 12:44:23PM +0300, max wrote: > I want to write a function whose behavior is as follows: > > foo "string1\nstring2\r\nstring3\nstring4" = ["string1", > "string2\r\nstring3", "string4"] > > Note the sequence "\r\n", which is ignored. How can I do this? > >

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Anupam Jain
On Mon, Jan 2, 2012 at 3:14 PM, max wrote: > I want to write a function whose behavior is as follows: > > foo "string1\nstring2\r\nstring3\nstring4" = ["string1", > "string2\r\nstring3", "string4"] > > Note the sequence "\r\n", which is ignored. How can I do this? Here's a simple way (may not be

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Steve Horne
On 02/01/2012 09:44, max wrote: I want to write a function whose behavior is as follows: foo "string1\nstring2\r\nstring3\nstring4" = ["string1", "string2\r\nstring3", "string4"] Note the sequence "\r\n", which is ignored. How can I do this? Doing it probably the hard way (and getting it wrong)

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Christian Maeder
Am 02.01.2012 10:44, schrieb max: I want to write a function whose behavior is as follows: foo "string1\nstring2\r\nstring3\nstring4" = ["string1", "string2\r\nstring3", "string4"] Note the sequence "\r\n", which is ignored. How can I do this? replace the sequence by something unique first, i

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Simon Hengel
> Doesn't the function "lines" handle different line-endings? > (In the Prelude and in Data.List) It does not ignore "\r\n". Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread max
В Mon, 2 Jan 2012 10:45:18 +0100 Yves Parès пишет: Prelude> lines "string1\nstring2\r\nstring3\nstring4" ["string1","string2\r","string3","string4"] > Doesn't the function "lines" handle different line-endings? > (In the Prelude and in Data.List) > > If not, doing this with parsec would be easy

Re: [Haskell-cafe] How to split this string.

2012-01-02 Thread Yves Parès
Doesn't the function "lines" handle different line-endings? (In the Prelude and in Data.List) If not, doing this with parsec would be easy (yet maybe slightly overkill...) 2012/1/2 max > I want to write a function whose behavior is as follows: > > foo "string1\nstring2\r\nstring3\nstring4" = [