Question
In Haskell, I want to write a function( squareNeg2 ) which takes a list and returns a list that if there is a negative value
In Haskell,
I want to write a function(squareNeg2) which takes a list and returns a list that if there is a negative value in the list, then squares the value.
The meaning of squareNeg1 and squareNeg2 is same, but squareNeg2 should use 'map' and 'either' function.
squareNeg1 :: (Ord a, Num a) => [a] -> [a] squareNeg1 [] = [] squareNeg1 (x:xs) | x <= 0 = x^2 : squareNeg1 xs | otherwise = x : squareNeg1 xs
ex. squareNeg1 [2,3,-1,-3,-5,4] [2,3,1,9,25,4]
=========================
squareNeg2 :: (Ord a, Num a) => [a] -> [a] squareNeg2 [] = [] squareNeg2 (x:xs) =
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started