SYB supports genuine gmap. [Was: Polymorphic updating with TC/TFs?]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SYB supports genuine gmap. [Was: Polymorphic updating with TC/TFs?]

oleg-30

adam vogt wrote
> Changing type parameters isn't supported by the ones I know (syb), but
> you can still fake it: <http://www.haskell.org/haskellwiki/SYB#fmap>.

SYB supports the type-changing generic map, of the signature
> gmap2 :: forall a b c . (Data a, Data b,
>                          Data (c a), Data (c b), Data (c X)) =>
>          (a -> b) -> c a -> c b

It was discovered back in 2008. Please see the following thread starting

http://www.haskell.org/pipermail/generics/2008-July/000349.html


The fake described in haskellwiki/SYB#fmap with unsafeCoerce is not
needed at all. There is a genuine gmap.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: SYB supports genuine gmap. [Was: Polymorphic updating with TC/TFs?]

Adam Vogt
Hi Oleg,

Interesting. I wasn't aware of that one when I wrote the "fake"
version. I can see one small disadvantage for the "real" one: many
hand-written data instances (ex. Data.Map) have defined:

  gunfold _ _    = error "gunfold"

So the "real" version will fail there. On the other hand, the gfoldl
defined in such instances is enough to support functions like
`everywhere (mkT (+ (1::Integer)))'.

For reference, the code moved from darcs.haskell.org to:
<http://code.haskell.org/generics/comparison/SYB1_2/>

Regards,
Adam

On Wed, Dec 18, 2013 at 4:06 AM,  <[hidden email]> wrote:

>
> adam vogt wrote
>> Changing type parameters isn't supported by the ones I know (syb), but
>> you can still fake it: <http://www.haskell.org/haskellwiki/SYB#fmap>.
>
> SYB supports the type-changing generic map, of the signature
>> gmap2 :: forall a b c . (Data a, Data b,
>>                          Data (c a), Data (c b), Data (c X)) =>
>>          (a -> b) -> c a -> c b
>
> It was discovered back in 2008. Please see the following thread starting
>
> http://www.haskell.org/pipermail/generics/2008-July/000349.html
>
>
> The fake described in haskellwiki/SYB#fmap with unsafeCoerce is not
> needed at all. There is a genuine gmap.
>
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe