I m trying to figure out a solution for Problem 27 of 99 Haskell questions.
Here s how I want it to be:
group :: (Eq a) => [Int] -> [[a]] -> [[[[a]]]]
group [] _ = []
group (i:is) xs
| sum (i:is) /= length xs = error "invalid arguments"
| otherwise = ...
联系的一个例子:
group [2,2,5] ["aldo","beat","carla","david","evi","flip","gary","hugo","ida"]
[[["aldo","beat"],["carla","david"],["evi","flip","gary","hugo","ida"]],...] (altogether 756 solutions)
因此,我想首先检查一下Int名单的总和是否与上述长处清单相同。 我认为,无论这两种价值观是否平等,都永远不印刷“无效的论点”。 我也试图这样做:
group (i:is) xs
| (sum (i:is) == length xs) = ...
| otherwise = error "invalid arguments"
still doesn t work
Any ideas?
<>UPDATES 我的无能为力。 职能中可收回的部分:
group (i:is) xs
| (sum (i:is) == length xs) = filter (/= []) $ concatGroups (combinations i xs) (group is xs)
| otherwise = error ("invalid arguments: " ++ show (sum(i:is)) ++ "/=" ++ show(length xs))
如你所知,<代码>组为xs,减少数额,但缩短时间,因此在休补时总是会提出申诉。 我认为,我只想去掉这一警卫,希望使用者永远不会这样做。