I have some trouble understanding this example:
data Row = R [Int]
deriving Show
data Matrix = M [Row]
deriving Show
check :: Matrix -> Int -> Bool
check (M matrix) n = foldr ((&&) . (\(R row) -> length row == n)) True matrix
test1 = check (M[R[1,2,3], R[4,5], R[2,3,6,8], R[8,5,3]]) 3 == False
I have this datatype named Row that contains a list of integers, and the Matrix datatype containing a list of rows. I have to check through my function if all rows have the length equal to the second parameter, n. I do not really understand why that foldr works. Let's look at test1. It starts by doing ((&&) . (lambda)) R[8, 5, 3] True
Isn't now, some sort of (f.g) x y which is f (g x y) ? If it is so, the result will be &&(lambda R[8, 5, 3] True) <-> && (True True), and Isn't the expresion in the paranthese evaluated first (True True) and it should give me an error ? Please make me understand what the order of execution is and where am I wrong.