haskell - Trying to understand recursion through a list of integers -
i learning how use recursion in haskell , trying understand how go through every element in list of integers , negate them. far can on final element of list know error lies in last line. best way go through every element in list rather final one?
negation :: [int] -> [int] negation [] = [] negation [n] = [-n] negation(x:xs) = negation xs
try using cons
operator :
put negated number @ front of list.
negation (x:xs) = -x : negation xs
if that, can rid of third line.
Comments
Post a Comment