[Haskell] An Alternative Data.List.Zipper

David Menendez dave at zednenem.com
Sat Jan 17 17:41:09 EST 2009

On Sat, Jan 17, 2009 at 4:32 PM, Jeff Wheeler <jeff at 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 correct (I think).

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'm undecided about allowing them to be empty. I don't know the theory
> or math behind zippers (I'm sure there are some papers written about
> it), but it doesn't make much sense to be empty. I got that impression
> from #haskell, also.

If you look at a zipper as a list with a selected element, then it
doesn't make sense to talk about a zipper of an empty list.

That being said, I'd prefer fromList to have the type [a] -> Maybe
(Zipper a), and similarly with next and previous. If people want to
live dangerously, they can use fromJust.

Dave Menendez <dave at zednenem.com>

More information about the Haskell mailing list