[Haskell] An Alternative Data.List.Zipper

Max Rabkin max.rabkin at gmail.com
Sat Jan 17 13:44:25 EST 2009


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 both
versions are strict in the spine of the list.

--Max

On Sat, Jan 17, 2009 at 10:33 AM, Jeff Wheeler <jeff at nokrev.com> wrote:
> 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 package implements a Zipper with
>
>> data Zipper = Zipper ![a] ![a]
>
> which allows for empty zippers, among other things. Very strange to me.
> It also seems unnecessarily strict. There are also no expected
> typeclasses implemented, like Foldable or Traversable.
>
> I thought it would be interesting to try fixing these problems with a
> much cleaner design, and I'd like to share what I came up with:
>
> http://hpaste.org/14030
>
> I'd very much appreciate some criticism of the code so that I can
> improve it.
>
> I'm not sure how best to provide this alternative on Hackage; should we
> make this merely a newer version of the old library, provide it in a
> conflicting package, or find a new namespace for it and provide it
> there?
>
> Thanks,
>
> Jeff Wheeler
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>


More information about the Haskell mailing list