I'm trying to make a hamming coding in haskell, i have a function "calculateParity" that takes a list of pairs [(Char, Int)] which are the bit (as Char) and the index (Int, starting at 1) in the list of bits, the second parameter is the position of the bit bit I'm going to calculate. The first thing that came to my mind was to use fold with the accumulator being the current parity of the data bits related to the parity bit. The code i wrote for this is like:
calculateParity :: [(Char, Int)] -> Int -> Char
calculateParity dataBits pos = intToDigit (foldl (\acc (bit, index) -> if pos .&. index /= 0 then acc xor (digitToInt bit) else acc) 0 dataBits)
When i try to compile it, this is the error:
? Couldn't match expected type ‘Int’
with actual type ‘(a0 -> a0 -> a0) -> Int -> t0’
? Probable cause: ‘foldl’ is applied to too few arguments
In the first argument of ‘intToDigit’, namely
‘(foldl
(\ acc (bit, index)
-> if pos .&. index /= 0 then acc xor (digitToInt bit) else acc)
0
dataBits)’
I think it says the intToDigit is not recieving an Int, but is it taking partial applied function, am i calling the foldl function wrongly?