I was recently reading learn you a haskell and I came across the expression:
[1,2] >>= \n -> ['a', 'b'] >>= \ch -> return (n, ch)
This expressions returns the result
[(1,'a'),(1,'b'),(2,'a'),(2,'b')]
so i understand that the monadic bind for lists is implemented as follows
xs >>= f = concatMap f xs
Taking the first half of the expression namely the:
[1,2] >>= \n -> ['a', 'b']
it evaluates to ['a','b','a','b']
, from what I understand this is then fed in to the function: (\ch -> return (n , ch))
.
What I don't understand is how the values 1,2 from the list are assigned to n and then how the compiler keeps a record of it to then assign it to n in the last function?