[Hs-Generics] Re: compositional gMap in SYB1

Alexey Rodriguez mrchebas at gmail.com
Tue Jul 29 09:50:24 EDT 2008

On Tue, Jul 29, 2008 at 9:51 AM, <oleg at okmij.org> wrote:

> Hello!
> Claus wrote:
> > Perhaps we can combine our versions to get the best of both?
> I have done so. I have committed a new version of
>        /comparison/SYB1_2/GMap.lhs
> with gmap2 of the type
> > gmap2 :: forall a b c . (Data a, Data b,
> >                          Data (c a), Data (c b), Data (c X)) =>
> >          (a -> b) -> c a -> c b
> The compositionality tests seem to pass. There are no unsafe
> operations or any unsafe extensions. Only standard Data.Typeable and
> Generics.Data operations are being used. The code also contains an
> optimization: if it is determined that a structured value has no
> components to map, no traversal is performed and the value is returned
> as it is. That should speed things up a little. The trick is producing
> something out of nothing.

That's a clever combination of both techniques. You are passing around an
explicit type representation at run-time, to ensure that the transforming
function applies only to X-positions. Also you don't pretend that there are
X-values in there (as Claus' version did) so there is no need for

One question: the runtime checks in traverse are for internal consistency
only, right?. I could not think of runtime errors arising from gmap2-calls.
Furthermore, I think the issue of unfold errors is solved, right? (Although
these properties are not known by the type system.)

>        Too bad that the deadline to amend a Haskell workshop paper
> has passed, and so has the deadline for the generics workshop. Perhaps
> we should write a separate paper?

Yes, that's a pity. I will mention this in the presentation though (and
update the technical report, which admittedly is rather delayed).

>        I'm afraid I would be out of town again for two weeks and so
> would not be able to follow the discussion closely.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/generics/attachments/20080729/54f1332d/attachment.htm

More information about the Generics mailing list