I'm working with the sop-core library, and I want to write a function with the following type:
patch :: NS I xs -> NP Maybe xs -> NP Maybe xs
xs is a type-level list of types like '[Int,Char,Bool]. I is an identity functor. NS I xs is an n-ary sum type. NP Maybe xs is an n-ary product where each component may or may not exist.
patch should take the value from the n-ary sum and fill the corresponding slot of the n-ary product, overwriting it if it already exists. For example:
patched :: NP Maybe '[Int,Char,Bool]
patched = patch (Z (I 3)) (Nothing :* Nothing :* Nothing :* Nil)
-- patched == Just 3 :* Nothing :* Nothing :* Nil
I suspect the solution might involve the injections function, but I'm stumped.