2
votes

Not using the fact that the Integer type belongs to the Show class define a function

integerTostring :: Integer -> String

Hint: use the function

unfoldr :: (b-> Maybe(a,b))->b->[a])

from the List module, defined by the formula

unfoldr f b=
            case f b of
                  Nothing -> []
                  Just (a,b) -> a : unfoldr f b



where
**data Maybe a = Nothing| Just a deriving (Eq, Ord, Read, Show)**

The Char module exports the function

intToDigit :: Int -> Char

the standard prelude offers the following method of the class Enum:

fromEnum :: (Enum a) => a -> Int

and the Integer type belongs to the Enum class...

What I did is:

   import List, Char
    integerToString :: Integer -> String
    integerToString = reverse.unfoldr(\a -> if a>0 then Just(IntToDigit$fromEnum$a'mod'10,a'div'10)else Nothing

Is that what i had to do? if not then what to do ?

1
The easiest way to tell whether you got it or not, is to just try it out in the interpreter.hammar
If you are in doubt about the requirements of an assignment, it's best to consult with the one who will grade it.Dan Burton
If you would alter your condition |if a>0| you could also handle negative values.Alessandro Vermeulen
Wouldn't want you to cheat, but the Haskell Report has showInt which "extends" showIntAtBase. Pretty solid math, but mostly out of scope for you. Now, if you want to see some insane arithmetic, check out showFloat.eternalmatt
integerToString == flip replicate $ "1" -- Base 1Theo Belaire

1 Answers

2
votes

Yeah, that's a good solution, although you forgot to handle negative integers and 0. Also, I suggest using the divMod function instead of using div and mod seperately.