PEZ: the Potentially-Excellent Zipper library release

19/04/2011

I’m happy to announce the release of a zipper library I named PEZ! I’ve been learning and building this silly library almost as long as I’ve been learning haskell. It’s not as great as it could be, but I’m releasing it now because it’s about time.

You can check it out with a:

cabal install pez

The library provides a generic zipper that can be used on all types in the Typeable class, for which the user defines (or generates) lenses from the excellent fclabels package.

Since Typeable instances are deriveable in GHC and fclabels lenses can be generated with a line of TH code, this makes for a very pain-free and intuitive zipper.

The Typeable class gives us the ability to move up and down through complex mutually-recursive structures, even “down through” reversible computations!

The lenses from ‘fclabels’ give us a way of referring to elements in data types in a way that is composable, allowing us to store our history as continuations and provide powerful mechanisms for “saving” a path through a data structure.

There is more to do: in particular I haven’t yet examined any of the performance characteristics of the approach I take, but please try it out and let me know how it works for you!

No Comments

A State Monad with dynamically-typed state

9/12/2010

Haskell’s standard State monad types allow the programmer to define a computation that works with some state in a way that looks and feels similar to using mutable state in an imperative language. However these State monad types are limited in that the type of the state cannot change during the computation.

Normally this is fine, but what if we really wanted to use the mechanics of a state monad to pass some state value that changed type, e.g. some mutually-recursive tree structure we would like to traverse?:
Read the rest of this article »

No Comments

New version of ‘thrist’ package released

13/11/2010

I’ve been collaborating with Gabor Greif on a new version of his ‘thrist’ module, which was just released last night! I approached Gabor with some new ideas that came to me as I was writing a module that uses Thrists heavily, and he invited me to co-author this version. (See below for a brief explanation of Thrists).

I noticed that in the previous version, the function foldThrist was essentially a foldr with a type signature that was overly restrictive.

For instance, one could not define an identity function on Thrists in terms of the foldThrist function, the way one can with regular lists, e.g.:

foldr (:) [] [1..4] == [1,2,3,4]

Other additions followed as I tried to define the Thrist equivalent of many useful list functions. For example I wanted to define a foldl-like function that we could use to reverse a Thrist.

Check out the release announcement on Gabor’s blog, along with his draft paper on Thrists.
Read the rest of this article »

No Comments