I have a list of functions accepting the same type as an input, different types as output
[ f_i : Mytype -> res:Sometype_i ]
Which operation can merge them into one function of the following type ?
f : Mytype -> \Product_i Mytype_i
Identically, if I have a list of functions returning the same type
[ f_i : Mytype_i -> res:Sometype ]
Which operation can merge them into one function of the following type ?
f : \Product_i Mytype_i -> Mytype list
It would be some canonical “preCombinator” or “postCombinator”.
(I imagine it has a name in FP..)
The answer to your first question is that you cannot do that in general. A list is a data structure with dynamic length, but the length of the resulting tuple has to be known statically at compile time. (You could construct the resulting tuple using reflection and use it as
obj, but that’s not really useful.)In the second case, you want to turn a list of functions into a function returning list, which can be done (both have dynamic length). You can write something like:
The primitive operation (passed to
fold) is a function that takes a function of typeTInp -> TOut listand a functionTInp -> TOutand combines them into a function returning a longer list. So you could also write: