[Haskell-cafe] uniplate (was: code review?)
jwlato at gmail.com
Mon May 30 23:56:54 CEST 2011
Hi Neil, thanks for the response.
On Mon, May 30, 2011 at 8:48 PM, Neil Mitchell <ndmitchell at gmail.com> wrote:
> Hi John,
> >> > While I'm on the topic, I recently wrote a tool that wanted to
> >> > traverse deep data structures as produced by haskell-src-exts. ?I
> >> > wound up with about 50 lines of case expressions and around the time
> >> > my hands were literally beginning to hurt decided that enough was
> >> > enough and I should try a generic approach. ?I heard uniplate was
> >> > pretty easy to use, and was pretty pleased to turn the entire thing
> >> > into a single line. ?It took me a little longer to figure out I needed
> >> > to use universeBi since all the examples were monotyped, but once I
> >> > did it Just Worked. ?Amazing. ?So thanks again! ?And maybe you could
> >> > mention universeBi in the instant introduction?
> >> Yes, I probably should - I'll try and get to that. Of course, I'd also
> >> happily accept a patch against
> >> http://community.haskell.org/~ndm/darcs/uniplate
> >> I use Uniplate inside HLint, and it's invaluable - there are a lot of
> >> times when List Comp + universeBi really hits the spot.
> > Does Uniplate include an instance for:
> >> instance Uniplate a => Biplate [a] a
> No, it only includes:
> instance Biplate [Char] Char where
> biplate (x:xs) = plate (:) |* x ||* xs
> biplate x = plate x
> I am slightly curious why I didn't include the more general a instead
> of Char version, but perhaps it doesn't quite work - polymorphic
> versions of the Direct instances can have problems if you pick weird
> types. I'll have a think, and if it does always work, I'll include it.
> Note that if you use the Typeable or Data versions this instance is
> automatically available. In practice I almost always end up using the
> Data versions of Uniplate, they require no instance definitions are
> are good to get started with - you can switch to Direct only if you
> need the additional performance.
I started with Data, but writing the Direct instance was so simple that I
didn't see a reason not to do it. My type doesn't have many constructors
yet though, and several of them aren't recursive, so maybe it was easier
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe