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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -