I have the following code that finds the divisors of an Integer, then all the subsets of the divisors, then sums all the divisors in each subset, then tests to see if that Integer is represented in the list of summations. In findWeird this is performed over a list of Integers.
allSubsets :: (Integral a ) => [a] -> [[a]]
allSubsets [] = [[]]
allSubsets ( n : nr ) = allSubsets nr ++ map (n:) (allSubsets nr)
sumAllSubsets :: (Integral a ) => [a] -> [a]
sumAllSubsets s = map sum (allSubsets s)
allDivisors :: (Integral a) => a -> [a]
allDivisors 0 = []
allDivisors n | n > 0 = [d | d <- [1..n], n `mod` d == 0]
| n < 0 = -1 : allDivisors (-n)
findWeird :: (Integral a) => [a] -> [a]
findWeird [] = []
findWeird (n:nn) = ( if n `elem` (AS.sumAllSubsets (DFL.allDivisors))
then []
else [n]) ++ findWeird nn
Problem is that I get the error:
test.hs:15:61:
Couldn't match expected type `[a]' with actual type `Integer -> [Integer]' In the first argument of `sumAllSubsets', namely `(allDivisors)' In the second argument of `elem', namely `(sumAllSubsets (allDivisors))' In the expression: n `elem` (sumAllSubsets (allDivisors))
But as far as know allDivisors produces a [Integral] and sumAllSubsets takes an [Integral], so I was just wondering if anyone could help. Thanks.