-7

Write a function of higher order atEach f xs applying the default function f to each element of the list xs.

atEach succ [1 to 5] = [2,3,4,5,6]
atEach length ["Haskell", "go", "forward"] = [7,5,8]
Mat
  • 202,337
  • 40
  • 393
  • 406
  • 4
    Why not `atEach length ["Haskell", "go", "forward"] = [7, 2, 7]`? If so, you are being asked to rewrite the standard `map` function. **What have you tried?** – dave4420 May 06 '13 at 09:11
  • @AntonGuryanov Please don't do the OP's homework for him, he will not learn. (Help him: yes; do it for him: no.) – dave4420 May 06 '13 at 10:01
  • @dave4420 OK, deleted my comment :) – Anton Guryanov May 06 '13 at 10:11
  • Yeah, this just looks like your standard `map` function – rafalio May 06 '13 at 12:01
  • yes, it's for my homework and I would like concrete assistance –  May 06 '13 at 12:56
  • https://docs.google.com/document/d/1ky6tSD5Z63UI2xJx5beZvdLgcva2iWZeDP5bnwYJ-wc/edit?usp=sharing How to I am writing the homework, I was wondering if you could help me –  May 06 '13 at 13:38
  • possible duplicate of [How would you define map and filter using foldr in Haskell?](http://stackoverflow.com/questions/5726445/how-would-you-define-map-and-filter-using-foldr-in-haskell) – Daniel Wagner May 06 '13 at 15:09

1 Answers1

5

As dave4420 already pointed out, your atEach seems to be the standard map function (please clarify if not). If this is the case, you have different ways to implement it, e.g.:

-- direct recursion
atEach _ [] = []
atEach f (x:xs) = ??? 

-- list comprehension
atEach f xs = [??? | x <- xs]

--using a fold
atEach f = foldr ??? []

I don't want to spoil the fun, so you can try to fill out the ???.

Landei
  • 54,104
  • 13
  • 100
  • 195