[Hs-Generics] Re: gMap in SYB1
oleg at okmij.org
oleg at okmij.org
Tue Jul 1 07:46:33 EDT 2008
Hello!
It has occurred to me a year ago that the type-changing gMap
is easily possible in SYB. The recent discussion has prompted me to
implement that solution. I have committed a patch to
http://darcs.haskell.org/generics/comparison/SYB1_2/GMap.lhs
with the implementation. I hope this is OK: the previous version of
that file was a stub saying that gMap is not supported. The function
gMap has the expected type
gmap :: (Data a, Data b, Data x, Data y) => (a -> b) -> x -> y
There are no unsafe operations used; there is not a single occurrence
of insafePerformIO and the ilk. Incidentally, Data.Generics could, in
principle at least, be implemented using a safe cast. Of course gmap
is not a total operation: one can't really expect (gmap id True) to
produce a character. It seems that gunfold is not total anyway.
Regarding the instance of Data for functions: SmashA does
define (co-variant) traversal `under lambda'. For example, we can
(gmap fromEnum) on a function and convert (Bool->Bool) to (Bool->Int).
Please see testt3 in
http://darcs.haskell.org/generics/comparison/SmashA/Syb4A.hs
I do not claim to have any use for that transformation, but it was
easy to implement...
I will be out of town for two weeks and so unlikely to
participate in further discussions until I come back.
Cheers,
Oleg
More information about the Generics
mailing list