Question

Hi everyone, I need help in Haskell Please 1) Write a function that takes a two-operand...

Hi everyone, I need help in Haskell Please

1) Write a function that takes a two-operand integer function and a list of Ints, and applies the function to each in the list twice. it is OK to call the map in the function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

According to the question, a function that takes a two-operand integer function(here function 'mulList') and a list of 'Ints',

and applies the function to each in the list twice.

mulList is given as:

mulList :: Num a => [a] -> a -> [a]
mulList [] y = []
mulList (x:[]) y = (x * y):[]
mulList (x:xs) y = (x * y): (mulList xs y)

Map returns a list constructed by appling a function (the first argument) to all items in a list passed as the second argument.

Lets first create a function that applies to the list once.

import Data.Char  
import Prelude hiding (map)
map :: (a -> b) -> [a] -> [b]
map _ [] = []
map f xs = [f x | x <- xs] //function f= mulList in our case.
This function takes two arguments:

1.a function f which maps as to bs, and

2.a list xs of as. It returns a list of bs which are the results of applying f to every member of xs.

for example, map square [1,1,2,3,5,8] would yield the list [1,1,4,9,25,64].

To apply the function to each in the list element twice

just do the following

f w = concat (map mulList (mulList w))
OR

import Control.Monad; f = mulList >=> mulList

Hope this may help you

Thank you ??

Add a comment
Know the answer?
Add Answer to:
Hi everyone, I need help in Haskell Please 1) Write a function that takes a two-operand...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT