The operation you are trying to is abstracted in Haskell using the higher-order function map. Commonly, we want to take a list or other sequence of data and perform an operation (function) on each element of the list. In non-functional languages, we would need to explicitly write a for-loop through each element (ie
for (int i = 0; i < array.length; i++) {
array[i] = doSomething(array[i]);
}
Of course in Haskell and other functional languages use of mutable state and explicit iteration aren't used in most circumstances so new functional programmers go "Iteration is the same as recursion so I'll write a recursive function instead something like:
recursiveIteration :: [a] -> [a]
recursiveIteration [] = []
recursiveIteration x:xs = $$ Lots of operations using x $$ : recursiveIteration xs
Of course, the lazy intermediate functional programmer after writing this function a few times realizes that "I'm using a functional language, why not abstract the operations using x using a function and pass the function as a parameter. Something like this:
recursiveIterationAbstractOperations :: (a -> b) -> [a] -> [b]
recursiveIterationsAbstractOperations _ [] = []
recursiveIterationsAbstractOperations func x:xs = func x : recursiveIterationsAbstractOperations func xs
I would write it as a map over the outer list and then process each inner element. Something like this:
discardparitybyte :: [[Bit]] -> [[Bit]]
discardparitybyte = map (take 8)
Learning to use higher-order functions like map, foldl, and filter making functional programming great. In my mind as an intermediate Haskell programmer, when I start using direct recursion especially when using lists, I stop myself and think about a better way to structure my code so that I can write it as a combination of these and other higher order functions because they allow for more modulatrity in the code.
-David