well-typed / generics-sop

Generic Programming using True Sums of Products
BSD 3-Clause "New" or "Revised" License
157 stars 48 forks source link

Should we add hapInjs'_POP #28

Closed phadej closed 7 years ago

phadej commented 7 years ago

The NP variant is simply hap injections, but POP variant is:

hapInjs'_POP :: SListI xss => POP f xss -> NP (K (SOP f xss)) xss
hapInjs'_POP = hmap (kfirst SOP) . hap injections . unPOP

which is quite lenghty. Or, is there a shorter way to say that?

kosmikus commented 7 years ago

So this is just apInjs_POP without the final call to hcollapse?

phadej commented 7 years ago

yes, except that apInjs_POP = map SOP . apInjs_NP . unPOP, i.e. it loses the structure in apInjs_NP already.

kosmikus commented 7 years ago

I assume you have a use case for this which doesn't involve collapsing the result?

phadej commented 7 years ago

It occurs when I need to hczipWith a constructor info (i.e. NP SOP.ConstructorInfo (SOP.Code a)).

kosmikus commented 7 years ago

It's actually a bit strange that the standard variants of apInjs apply hcollapse. So yes, I'm in favour of this as well. At least adding the two functions to Generics.SOP.NP. But they should be called apInjs'_NP and apInjs'_POP, without the h which is currently only used for the overloaded variants.

I'm also not opposed to adding a HApInjs class that offers the two functions in overloaded form.

I'd appreciate a PR, but if you don't get around to it, I might try to do it myself.

phadej commented 7 years ago

I'll make a PR with apInjs'_POP and apInjs'_NP; let's see if I'll get HApInjs to work too.