how to create my own map using another function i defined in haskell

Viewed 54

I am trying to create map using another function that I have been supplied with can anyone help so

I have created:

ConcatListsOnFunc :: (a -> [b]) -> [a] -> [b]
ConcatListsOnFuncf []     = []
ConcatListsOnFunc func (y:ys) = func y ++ flattenMap func ys 

and i was wondering how i can use that function above to implement the higher order function map

which is of type

myMap :: (a -> b) -> [a] -> [b]

from myMap with input (+1) [1,2,3] should give output [2,3,4]

can anyone help is there a way to create myMap using my previously defined function with a lambda function?

1 Answers

You can wrap items in a singleton list, so:

myMap :: (a -> b) -> [a] -> [b]
myMap f = concatListsOfFunc (\x -> [f x])
Related