Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>let foo = bar in ...</code> simply defines <code>foo</code> to be the exact same thing as <code>bar</code> within the context of <code>...</code>; you could simply use textual substitution to replace all uses of <code>foo</code> in <code>...</code> with <code>(bar)</code> and get the exact same result.</p> <p><code>where</code> clauses are similar to <code>let...in</code> expressions, but go at the end of a function clause, instead of being an expression. For instance,</p> <pre><code>foo x | p1 = ... y ... | p2 = ... y ... where y = ... </code></pre> <p>There is no way to rewrite this with <code>let...in</code> without changing the guards into <code>if...then...else</code>s. Often, <code>where</code> clauses are used over <code>let...in</code> clauses purely for reasons of style.</p> <p>The bind operator is something different entirely. It's used in <code>do</code> notation to "extract" a value from a monadic computation. That is, if <code>foo</code> has the type <code>m a</code>, then after <code>x &lt;- foo</code>, <code>x</code> has the type <code>a</code>. All the other "binding" forms just define names, but <code>&lt;-</code> is used for <em>binding</em> a computation's result to a name from within a monad. <code>&lt;-</code> can only be used inside a <code>do</code> block, so it's exclusively used to build up a larger computation in the same monad as the action you're binding the result of.</p> <p><code>let foo = bar</code> in <code>do</code> notation is just a convenience; you can rewrite:</p> <pre><code>do let foo = bar ... </code></pre> <p>as</p> <pre><code>let foo = bar in do ... </code></pre> <p>but that gets messy when you have a lot of such bindings, as the <code>do</code> blocks get nested deeper and deeper.</p> <p>I don't know what the advice you mentioned is talking about; you can define multiple variables in a <code>let...in</code> block just fine, and</p> <pre><code>let foo = ... bar ... in ... </code></pre> <p>is more idiomatic than</p> <pre><code>let foo = ... in let bar = ... in ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload