fork(5) download
  1.  
  2. {-# OPTIONS_GHC -Wall #-}
  3.  
  4.  
  5. toDigits :: Integer -> [Integer]
  6. toDigits a
  7. | a<=0 =[]
  8. |otherwise = reverse(toDigitsRev(a))
  9.  
  10.  
  11. toDigitsRev :: Integer -> [Integer]
  12. toDigitsRev a
  13. | a<=0 =[]
  14. | otherwise = mod a 10 : toDigitsRev (div a 10)
  15.  
  16.  
  17. intListLength :: [Integer] -> Integer
  18. intListLength [] = 0
  19. intListLength (x:xs) = 1 + intListLength xs
  20.  
  21. doubleEveryOther :: [Integer] -> [Integer]
  22. doubleEveryOther [] = []
  23. doubleEveryOther [a] = [a]
  24. doubleEveryOther (a:b:fin)
  25. | (intListLength (a:b:fin) `mod` 2 <= 0 )= a*2:b:doubleEveryOther fin
  26. | otherwise = a: b*2 :doubleEveryOther fin
  27.  
  28. sumDigits :: [Integer] -> Integer
  29. sumDigits [] = 0
  30. sumDigits (a:as) = sum(toDigits a) + sumDigits as
  31.  
  32. validate :: Integer -> Bool
  33. validate a = (mod (sumDigits(doubleEveryOther(toDigits a))) 10 <= 0)
  34.  
  35.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:1:0: The function `main' is not defined in module `Main'
stdout
Standard output is empty