[Haskell-cafe] Re: Looking for practical examples of Zippers
David Menendez
dave at zednenem.com
Wed Apr 1 01:54:44 EDT 2009
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.
data Expr = Var String | Lit Int | App Expr Expr | Abs String Expr
data ExprCtx = AppC1 Expr | AppC2 Expr | AbsC String
data ExprZ = ExprZ { ctx :: [ExprCtx], focus :: Expr }
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.
--
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
More information about the Haskell-Cafe
mailing list