[Haskell] An Alternative Data.List.Zipper

Jeff Wheeler jeff at nokrev.com
Sat Jan 17 19:49:05 EST 2009

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 them yet. :)

> 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.

Apparently a zipper can be empty, as the focus is the rest of the list,
not the current element. It seems that my file is not a Zipper, but
rather a PointedList (thanks to roconner in #haskell). Therefore, I've
changed my file to use the new name throughout, including a new module

With this change, I think it's now appropriate to post on Hackage.

> 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.

I agree, and I've made this change. I found this annoying on
next/previous though, so I've created a tryNext/tryPrevious that'll
return an unchanged PointedList if it's already on the end.

Here's the new version: http://hpaste.org/14030#a5

Thanks for the feedback,

Jeff Wheeler

More information about the Haskell mailing list