[Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-04 Thread R J
Could someone provide an elegant solution to Bird problem 4.2.13? Here are the problem and my inelegant solution: Problem --- Since concatenation seems such a basic operation on lists, we can try to construct a data type that captures concatenation as a primitive. For example, data (CatL

Re: [Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-04 Thread Rafael Gustavo da Cunha Pereira Pinto
Mine is somewhat more elegant... data (CatList a) = CatNil | Wrap a | Cat (CatList a) (CatList a) deriving Show instance (Eq a) => Eq (CatList a) where CatNil == CatNil = True Wrap x == Wrap y = x==y a@(Cat x y) == b

Re: [Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-04 Thread Ryan Ingram
2009/3/4 R J : > What's the pure solution that uses cases and recursion on > CatList, not Haskell's built-in lists, to capture the equality of nested > CatLists? As Rafael pointed out, the simplest thing to do is to convert to a canonical form; you can prove that each CatList has a single canonica

Re: [Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-04 Thread Rafael Gustavo da Cunha Pereira Pinto
Good point Ryan, I did it in my lunch time and, being in a hurry, overlooked the fact that left adjust in (*2) is redundant and that (*1) can be completely removed by using (adjust x). I actually think I added (*2) for "safety"!! :-D R J, you should take a look on Chris Okasaki's book. This is pr

Re: [Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-07 Thread Bas van Dijk
2009/3/4 R J : > Could someone provide an elegant solution to Bird problem 4.2.13? > > Here are the problem and my inelegant solution: > > Problem > --- > > Since concatenation seems such a basic operation on lists, we can try to > construct a data type that captures > concatenation as a primit