
Write a function with three parameters, two atoms and a list, (say p1, p2 and L) that returns the list, L, with all occurrences of the first given atom, p1, replaced by the second one, p2. If P2 be nil, the given atom should be deleted and the returned list cannot contain anything in place of it, no matter how deep it occurred in the list. Note: Remember it says that "no matter how deep it occurred in the list.".It means thatwe may have nested list example: replace 1 2 [1 2 3 4] => [2 2 3 4] replace 1 2 [[1 2 3][3 4 5 1]] => [[2 2 3][3 4 5 1]] --------------------------------- Ahhh...imagining that irresistible "new car" smell? Check outnew cars at Yahoo! Autos.

Hi
Write a function with three parameters, two atoms and a list, (say p1, p2 and L) that returns the list, L, with all occurrences of the first given atom, p1, replaced by the second one, p2. If P2 be nil, the given atom should be deleted and the returned list cannot contain anything in place of it, no matter how deep it occurred in the list.
Is this homework? http://www.haskell.org/haskellwiki/Homework_help
example: replace 1 2 [1 2 3 4] => [2 2 3 4] replace 1 2 [[1 2 3][3 4 5 1]] => [[2 2 3][3 4 5 1]]
If it is, use Lisp. Try assigning a type to this in Haskell, its not particularly easy, and would require clever type class stuff. Thanks Neil
participants (2)
-
hossein rohani
-
Neil Mitchell