0

Really not very good at this language and I need to make a function that can check if a number is perfect, this is what I have so far but it isn't working.

   import System.IO

main = do
putStrLn "Please enter a number: "
n <- getLine
perfectnumber n = let n == sum [i | i <- [1..n-1], n `mod` i == 0]
  • I'm a bit curious why you have the idea that this would work. It contains some parts that are quite good, but some parts are simply invalid Haskell. So perhaps it is worth isolating the good parts, and trying to rebuild the rest. – Willem Van Onsem Mar 07 '18 at 19:30

1 Answers1

0

solved this as:

perfect :: Integral a => a -> Bool
perfect n = n == sum [i | i <- [1..n-1], n `mod` i == 0]