[Haskell-cafe] Re: Looking for practical examples of Zippers
wren ng thornton
wren at freegeek.org
Wed Apr 1 20:10:54 EDT 2009
David Menendez wrote:
> On Tue, Mar 31, 2009 at 11:44 PM, wren ng thornton <wren at freegeek.org> wrote:
> > Another tricky thing for this particular example is answering the question
> > of what you want to call the "focus". Usually zippered datastructures are
> > functors, so given F X we can pick one X to be the focus and then unzip the
> > F around it.
>
> The functor part isn't important. You can make a zipper from any
> recursive structure.
This seems at odds with the below
> In general, if I have a type T and functors F and F' such that T is
> isomorphic to F T and F' is the derivative of F, then ([F' T], T) is a
> zipper for T.
Right, for any equi-recursive type we can rewrite it as an iso-recursive
type (Fix F ~ F (Fix F)) and the rest follows. But the F we feed into
the fixed-point is a functor, otherwise Fix isn't going to like it;
which goes against the claim that functorness isn't important.
I didn't mean that T itself needs to be a functor, only that most often
T = Fix F for some F, and the functorness of F is the helpful bit.
Perhaps I was unclear. Of course, if T _is_ a functor then we can take
the derivative of T instead, which may be sufficient for the task; I'd
still call this a zipper. (The derivative of F is implicit here, but it
can be hidden which is good for abstract types.)
The point I was making, though, is that the abstract type "Map" is in
fact smaller than the recursive type defined by the ADT we use to model
it. For the type defined only by the ADT: convert to iso-recursion, take
the derivative, and voila. But for the abstract type the ADT
approximates, it's not as easy.
--
Live well,
~wren
More information about the Haskell-Cafe
mailing list