So I have a function which has to have a certain type. My implementation is similar to the following:
f :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
f t1 t2 t3 t4 t5 t6 t7 t8 t9
= filterFirst checkFunc p
where
p = findAll [1..9]
checkFunc = validate t1 t2 t3 t4 t5 t6 t7 t8 t9
Now is there any way I could abbreviate the t values to either change validate and then rearrange f or something similar the following:
f :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
f ts
= filterFirst checkFunc p
where
p = findAll [1..9]
checkFunc = validate ts
A way to make this look cleaner would be amazing.
Edit: More Detail
validate :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> [Int] -> Bool
validate t1 t2 t3 t4 t5 t6 t7 t8 t9 is =
[t1, t2, t3, t4, t5, t6, t7, t8, t9] == sums is
-- Calculates sums from specific indexes in list
sums :: [Int] -> [Int]
-- from https://stackoverflow.com/a/28904773/1218369
filterFirst :: (a -> Bool) -> [a] -> [a]
-- Find all possible permutations
findAll :: [a] -> [[a]]
-- Basically Data.List (permutations)
The problem is f must have the values passed as parameters. I was looking and even some function that takes any number of parameters and produces a list would be helpful but I can't seem to find any module with such function.