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

Hi Stephen,
From: Stephen Tetley
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

On 8 February 2010 11:16, John Lato
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.
Hi John, Most definitely! - 'making a functor' is one of the strategies / patterns to consider when designing data types. It would be nice if there was a reference listing and defining such strategies. Phantom types are another strategy (well, maybe a family of strategies if you look closely), as is the de-normalisation by 'moving the sum' that I mentioned previously in the thread, albeit on a smaller scale. Best wishes Stephen
participants (2)
-
John Lato
-
Stephen Tetley