Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

=+ Reserves $100,000 Deposits $500,000 Loans 400,000

Answered: 1 week ago