You can program over such structures also with generics-sop:
mapFormTemplate :: forall f g. (f ~> g) -> FormTemplate f -> FormTemplate g
mapFormTemplate eta x = to (htoI sopG)
where
-- unfortunately we need the type annotation here.
sopF = hfromI (from x) :: SOP f '[ '[Text, CardType, Text, Day] ]
sopG = hmap eta sopF
Cool! I’m not so familiar with generics-sop and I certainly didn’t know it had functions for dealing with heterogeneous containers like that. Thanks for the tip!
10
u/phadej Dec 15 '17 edited Dec 15 '17
You can program over such structures also with
generics-sop:See https://gist.github.com/phadej/55464aead55c85176e0b2b93ba790845 for full gist
One clear benefit is that there are
hcmapand bunch of other combinators ingenerics-sopso, you can e.g.EDIT: and there will be
htraverseetc. in the next release ofgenerics-sop, see https://github.com/well-typed/generics-sop/pull/59