3 ms·
I don't read Haskell, and though I tried searching for it, I was unsuccessful, so I figured I'd ask. What's the "(card, rem) <- (selectOne deck)" notation mean
by iamwil 19y ago
I don't read Haskell, and though I tried searching for it, I was unsuccessful, so I figured I'd ask.
What's the "(card, rem) <- (selectOne deck)" notation mean?
And does the "in" put the second if statement inside the else clause of the first if statement, or outside of it?
Thanks
- yummyfajitas 19y agoThe notation x <- f y means "f y returns a monadic value; take the next line (which is a monadic function) and apply it to x." Naively, you can think of x <- f y as pulling the value out of the monad. Now you can apply non-monadic functions to it. In a certain sense, this is true. However, by the time the do statement is finished, you will need to push it back in (the return statement). So you can only pull stuff out of the monad if you immediately put it back in (otherwise you get a type error). (card, rem) is simply unpacking a 2-tuple, containing the card and the remaining deck (after picking 1 element). The "let straight = ... in \newline (some statement)" means exactly what it sounds like. "let x = 3 in xx" means "take the statement xx, replace x by 3, you get 3*3=9".