所以我有一个函数
必须
有某种类型。我的实现类似于以下内容:
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
现在有没有办法把t值缩写为
或者类似的事情:
f :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
f ts
= filterFirst checkFunc p
where
p = findAll [1..9]
checkFunc = validate ts
一个让它看起来更干净的方法将会是惊人的。
编辑:
更多细节
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)