[Haskell-cafe] a beginner question: decorate-op-undecorate

John Lato jwlato at gmail.com
Mon Feb 8 06:16:03 EST 2010


Hi Stephen,

> From: Stephen Tetley <stephen.tetley at gmail.com>
>
> Hi John
>
> I'm not sure about making Binding polymorphic to get Functor,
> Traversable, Foldable...
>
> While I think you're correct that partitionEithers might not be a
> useful example to draw from in this case, I'd assume that Binding
> would be part of a larger syntax-tree, thus there might not be a
> appropriate single leaf to make the tree polymorphic on. Felipe
> Lessa's point - to use Uniplate or one of the Generics packages -
> might be a better candidate for implementing traversals.

I did not consider that, and hadn't seen any other replies when I
first replied.  If true, I would agree that one of the Generics
packages would be the best option.

Regardless, I think this is a valid approach.  By thinking of data in
terms of Functor, Traversable, etc., one can recognize these patterns.
 Even if Binding is part of a larger syntax tree and can't reasonably
be made polymorphic, creating an fmap-like function to do what the OP
requested is IMHO simple and idiomatic Haskell.  Using Generics then
simplifies the implementation.

Cheers,
John


More information about the Haskell-Cafe mailing list