I am trying to express the following map as a Haskell function:
Given two types a, b , we consider a family of functions F(a, b) consisting of functions of type
f :: a -> a -> ... -> a -> b
with n repetitions of a , where n is an integer greater than zero. I want to map each function f in F(a, b) to a function f' :: [a] -> b such that f x1 x2 ... xr = f' [x1, ..., xr] , where r less than the number of arguments f takes (i.e. I'm looking for a function listify :: F(a, b) -> ([a] -> b) ). If there are more elements than f takes arguments, additional elements should be discarded:
f :: a -> a -> b (listify f xs) == (listify f $ take 2 xs)
Also, if an empty string is passed, any value is acceptable.
Of course, I can implement this map for functions with a fixed number of arguments (for example: listify :: (a -> a -> b) -> ([a] -> b) , etc.), but I could not find a way to write a function that does this for all f in F(a, b) at the same time. Despite the fact that Template Haskell can probably provide me with the tools I need, I'm not interested in such a solution. I want to find a pure "magic" style.
Does anyone know if this is possible? Can someone point me in the right direction? Or is it a well-known "problem" that has been solved billions of times and I just can't find a solution?
types haskell higher-order-functions
morris
source share