Hello,
I have to do this :
Exercise 1 We need to first find the digits of a number. Define the
functions
toDigits :: Integer -> [Integer]
toDigitsRev :: Integer -> [Integer]
toDigits should convert positive Integers to a list of digits. (For 0 or
negative inputs, toDigits should return the empty list.) toDigitsRev
should do the same, but with the digits reversed.
Example: toDigits 1234 == [1,2,3,4]
Example: toDigitsRev 1234 == [4,3,2,1]
Example: toDigits 0 == []
Example: toDigits (-17) == []
I have this so far :
-- | convert a number to a array in pieces where a negative number will be a empty array.
toDigits :: Integer -> [Integer]
toDigits n
| n < 0 : []
| otherwise : n/10 : []
-- | Main entry point to the application.
module Main where
-- | The main entry point.
main :: IO ()
main = do
toDigits 123
but now I see this error message :
src/Main.hs@5:3-5:4parse error on input |
This is not homework because I do this as a self-study.
Roelof
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe