so I’m learning how to program in Haskell.
One thing I would like to see is adding 1 to each element of a list by using map and using recursion that doesn’t use a list comprehension and without using map or any other higher-order library function.
I thought it’d be pretty cool to see both ways of implementation.
If you understand what
mapdoes then I think it won’t be difficult to write what you intend to do. When you see the type ofmapSo it takes a function and a list and returns another list after applying that function to each element of the list. So for your intended purpose to add one to each element you can choose the function to be
(+1). SoNow defining your own function is easy if you understand the basic haskell. You can look at the source of
mapfor help.It gives you all the help you need to implement your recursive incrementing function like
Now try this in ghci