title: Understanding Haskell (<-) operator
body: <p>I was studying the code over at <a href="https://rosettacode.org/wiki/Zebra_puzzle#LP-like_version" rel="nofollow noreferrer">https://rosettacode.org/wiki/Zebra_puzzle#LP-like_version</a> and got somewhat confused. </p>
  
  <p>Here is a minimal example of what is going on in that code. </p>
  
  <pre><code>import Control.Monad
  import Data.List
  
  values :: (Bounded a, Enum a) =&gt; [[a]]
  values = permutations [minBound..maxBound]
  
  data Nation = English | Swede | Dane
    deriving (Bounded, Eq, Enum, Show)
  
  data Color = Red | Blue | Green
    deriving (Bounded, Eq, Enum, Show)
  
  answers = do
  
    nation &lt;- values
    begin nation English
  
    color &lt;- values
    end color Red
  
    return $ zip nation color
  
    where
      end xs x = guard $ last xs == x
      begin xs x = guard $ head xs == x
  
  main :: IO ()
  main = do
      forM_ answers $ (\answer -&gt;  -- for answer in answers:
        do
          mapM_ print answer
          putStrLn "----" )
      putStrLn "No more solutions!"
  </code></pre>
  
  <p>what is mysterious for me is what is happening in the do block. </p>
  
  <p>I understand from various sources that the <code>a &lt;- b</code> operator does an action <code>b</code> and binds it to <code>a</code>. But what is the action here exactly? </p>
  
  <p>I assumed it was <code>values</code> but if I comment out the <code>begin</code> and <code>end</code> function calls and definitions then haskell does not know what to do with <code>values</code> anymore. I guess this is because the equality test in their definitions is what lets haskell infer the type (am I wrong?). </p>
  
  <ol>
  <li>In that case what exactly <em>is</em> the <em>action</em> here?  </li>
  <li>Also how does <code>values</code> know which bounded type to apply <code>permutations</code> to? This part seems quite mysterious. </li>
  <li>Finally, if I wanted to keep the same
  code as above but modify it list out all permutations (not just the
  one that satisfy <code>begin</code> and <code>end</code>) how would I do it?</li>
  </ol>