[Haskell-beginners] accumenlator problem

Nishant nishantgeek at gmail.com
Wed May 13 12:04:53 UTC 2015


I think you wanted something like this :


toDigits :: Integer -> [Integer]
toDigits number
  | number <= 0 = []
  | number > 0 = toDigitsAcc [] number --( toDigits (number `div` 10) ) ++
[number `mod` 10]

toDigitsAcc:: [Integer] -> Integer -> [Integer]
toDigitsAcc acc number
 | number <= 0  = acc
 | number > 0 =  toDigitsAcc ((number `mod` 10) : acc) (number `div` 10)


Regards
Nishant Verma


On Wed, May 13, 2015 at 5:13 PM, Roelof Wobben <r.wobben at home.nl> wrote:

> Hello,
>
> I have this :
>
> -- | Convert a digit to a list for example 123 becomes [1,2,3]
> toDigits :: Integer -> [Integer]
> toDigits number
>   | number <= 0 = []
>   | number > 0 = toDigitsAcc [] number
>
> toDigitsAcc:: [Integer] -> [Integer] -> [Integer]
> toDigitsAcc acc number
>   | number <= 0  = acc
>   | number > 0 = (number `mod` 10) : acc toDigitsAcc (number `div` 10)
>
> bur there are error on both last lines of he functions.
>
> Any tips how to solve this ?
>
> Roelof
>
>
> ---
> Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
> http://www.avast.com
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Nishant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150513/a396b025/attachment.html>


More information about the Beginners mailing list