[Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread Jeff Wheeler
Hi, (I also sent this to libraries@, but without response; I'm posting here for a wider audience.) I'm somewhat of a beginner in Haskell, so take what I say with a grain of salt, please. The ListZipper implementation seems very odd to me, and #haskell seemed to agree with me. The current

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread Max Rabkin
This traverses the list three times (reverse, init and last are each linear time): fromListEnd xs = Zipper (reverse $ init xs) (last xs) [] But we only need to do it once: fromListEnd xs = let x:xs' = reverse xs in Zipper xs' x [] I don't *think* this has an effect on strictness/laziness, since

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread Jeff Wheeler
On Sat, 2009-01-17 at 10:44 -0800, Max Rabkin wrote: This traverses the list three times (reverse, init and last are each linear time): fromListEnd xs = Zipper (reverse $ init xs) (last xs) [] But we only need to do it once: fromListEnd xs = let x:xs' = reverse xs in Zipper xs' x [] I

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread Jeff Wheeler
On Sat, 2009-01-17 at 21:55 +0100, Jean-Philippe Bernardy wrote: I think it should admit empty, and the traversable instance should traverse the first list in reverse. I fixed the latter issue so that the behavior is correct (I think). I tested it like this: forM (next $ next $ fromList

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread David Menendez
On Sat, Jan 17, 2009 at 4:32 PM, Jeff Wheeler j...@nokrev.com wrote: On Sat, 2009-01-17 at 21:55 +0100, Jean-Philippe Bernardy wrote: I think it should admit empty, and the traversable instance should traverse the first list in reverse. I fixed the latter issue so that the behavior is

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread Jeff Wheeler
On Sat, 2009-01-17 at 17:41 -0500, David Menendez wrote: That's correct, but I think you'd be better off defining OpApplicative (or Backward, as I call it) locally and avoiding the two reverses. I'll have to look into this more; I don't really understand applicatives right now, so I can't use

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread David Menendez
On Sat, Jan 17, 2009 at 7:49 PM, Jeff Wheeler j...@nokrev.com wrote: On Sat, 2009-01-17 at 17:41 -0500, David Menendez wrote: That's correct, but I think you'd be better off defining OpApplicative (or Backward, as I call it) locally and avoiding the two reverses. I'll have to look into this

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread roconnor
On Sat, 17 Jan 2009, David Menendez wrote: instance Applicative f = Applicative (Backwards f) where pure = B . pure f * x = B (unB f ** unB x) probably should be f * x = B (unB x ** unB f) anyhow, this should be part of Control.Applicative. This may be terminological confusion. I

Re: [Haskell] An Alternative Data.List.Zipper

2009-01-17 Thread David Menendez
On Sat, Jan 17, 2009 at 9:13 PM, rocon...@theorem.ca wrote: On Sat, 17 Jan 2009, David Menendez wrote: instance Applicative f = Applicative (Backwards f) where pure = B . pure f * x = B (unB f ** unB x) probably should be f * x = B (unB x ** unB f) I always get that backwards.