I am trying to combine an arbitrary number of mathematical functions that are on the list.
I wrote a build function that combines them:
chain :: (c -> d) -> (a -> b -> c) -> a -> b -> d
g `chain` f = \a b -> g (f a b)
So, let's do something like
let b = (*) `chain` (+) `chain` (-)
Creates a function that takes bcd and does ((a & minus; b) + c) & times; d
> b 2 3 4 5
> 15
My question is that I want to be able to link a set of them based on an arbitrary list:
[(*),(+),(-)] will result in (*) `chain` (+) `chain` (-)
[(*),(+),(-),(*)] will result in (*) `chain` (+) `chain` (-) `chain` (*)
Is it possible? I tried to use folds, but I can not get it to work, because the type of battery changes after each use of the element.
For example, the type of three functions connected together:
b :: Integer -> Integer -> Integer -> Integer -> Integer
But for four this:
b :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer
If someone can point me in the right direction or find out about a solution, that would be great! Thank.
EDIT:
My ultimate goal is to do something like this:
getZipList $ pure (function composing * and +) <*> ZipList [1,2,3] <*> ZipList [4,5,6]
<*> ZipList [7,8,9]
will result in:
[(1+4)*7, (2+5)*8, (3+6)*9]