[Haskell-cafe] Function to cast types

Gökhan San gsan at stillpsycho.net
Sun Mar 22 10:11:43 EDT 2009


Anonymous Anonymous <temp.public at gmail.com> writes:

> fromIntToString :: Int -> String

...

> PS: if possible please do not use any casting functions that are predefined.

This is a rather simplified version of the Show instance of Int from the
libs:

itos :: Int -> String
itos x | x < 0     = '-' : itos (negate x)
       | x < 10    = "0123456789" !! x : ""
       | otherwise = let (q, r) = x `quotRem` 10
                     in itos q ++ itos r

-- 

Gökhan San


More information about the Haskell-Cafe mailing list