[Haskell-beginners] list of integers to list of nats

kane96 at gmx.de kane96 at gmx.de
Sat Feb 20 06:39:30 EST 2010


Hi,
I have to write a function which maps a list of integers to a list of the corresponding nats. The following code is already there:

data Nat = Z | S Nat deriving (Eq,Ord,Show)

instance Enum Nat where
    toEnum i | i < 0        = error "Enum_Nat.toEnum: Negative integer"
             | i == 0       = Z
             | otherwise    = S (toEnum (i-1))

the function should be: mapIntsToNats :: [Int] -> Maybe [Nat]
so for example: [2,0,1,3] should make: [S (S Z), Z, S Z, S (S (S Z))]

how can I do that?



-- 
NEU: Mit GMX DSL über 1000,- ¿ sparen!
http://portal.gmx.net/de/go/dsl02


More information about the Beginners mailing list