All pastes #56041 Raw Edit

tail-rec map haskell

public text v1 · immutable
#56041 ·published 2006-05-15 21:43 UTC
rendered paste body
myMap :: (a -> b) -> [a] -> [b]
myMap f [] = []
myMap f lst = myReverse (iter f [] lst)
    where
        iter f lst1 [] = lst1
        iter f lst1 (x:xs) = iter f ((f x):lst1) xs

myReverse :: [a] -> [a]
myReverse [] = []
myReverse lst = iter [] lst
    where
        iter lst1 [] = lst1
        iter lst1 (x:xs) = iter (x:lst1) xs