Question: In Haskell, I want to write a code for a function ' Func1 ', which returns a list that each element is multiplied by 10
In Haskell,
I want to write a code for a function 'Func1', which returns a list that each element is multiplied by 10 when the element is negative.
The 'Func1' should use 'either' and 'map' functions.
ex. Func1 [1, -3, 4, -9] = [1, -30, 4, -90]
I wrote the code.
But, It shows an error at the 'Left x'. I don't know how to fix it.
Func1 :: (Ord a, Num a) => [a] -> [a]
Func1 [] = []
Func1 (x:xs) =
let f = either (\l -> if l < 0 then (10*) else l) id
in map (f (Left x)) (x:xs)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
