<div dir="ltr">Thanks, Alexis! Your explanation of the distinction between let and where is the first I've understood.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 8, 2017 at 9:05 PM, Alexis King <span dir="ltr"><<a href="mailto:lexi.lambda@gmail.com" target="_blank">lexi.lambda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">No, it isn’t a GHC parser error.<br>
<br>
Your preceding expression ends in a where clause, like this:<br>
<br>
   assertBool "4" $ p == Right a where<br>
       p = ...<br>
<br>
That’s fine, but make sure you understand how where works. Where clauses<br>
are not attached to individual expressions, they are *always* attached<br>
to definitions. In this case, the where clause is not attached to the<br>
assertion but to your definition of tHash. GHC parses your program the<br>
same way as this one:<br>
<br>
    tHash = TestCase $ do<br>
        ...<br>
        assertBool "4" $ p == Right a<br>
      where<br>
        p = ...<br>
<br>
Therefore, the where clause forces the termination of the do block,<br>
since it exists syntactically outside the “body” of a definition. It is<br>
its own syntactic construct, an optional sequence of definitions in<br>
scope within the RHS of a definition. You cannot have any more<br>
expression after the where clause because they would be free-floating,<br>
outside of any particular definition.<br>
<br>
If you really want definitions that are scoped to that single assertion,<br>
use a let expression instead of a where clause:<br>
<br>
    let p = ...<br>
        a = ...<br>
    in assertBool "4" $ p == Right a<br>
<br>
That works, since let...in blocks serve as completely ordinary<br>
expressions, and they are permitted anywhere an expression is permitted<br>
(unlike where clauses, which must “belong” to a top-level or let-bound<br>
definition).<br>
<br>
> On Sep 8, 2017, at 20:54, Jeffrey Brown <<a href="mailto:jeffbrown.the@gmail.com">jeffbrown.the@gmail.com</a>><br>
<span class="im HOEnZb">> wrote:<br>
><br>
> The test suite below[1] does what it's supposed to. The last line of<br>
> it is a commented-out test case:<br>
><br>
>     -- assertBool "broken" $ True<br>
><br>
> If I uncomment that, it fails to compile:<br>
><br>
>     > :reload<br>
>     [13 of 13] Compiling TParse           ( test/TParse.hs, interpreted )<br>
><br>
>     test/TParse.hs:67:3: error: parse error on input ‘assertBool’<br>
>        |<br>
>     67 |   assertBool "broken" $ True<br>
>        |   ^^^^^^^^^^<br>
>     Failed, 12 modules loaded.<br>
>     ><br>
><br>
> However, if I move it to somewhere earlier in the code, it works.<br>
><br>
><br>
> [1] <a href="https://github.com/JeffreyBenjaminBrown/digraphs-with-text/blob/e5afd39b950752ccb65997b89ab625d859299b4a/test/TParse.hs" rel="noreferrer" target="_blank">https://github.com/<wbr>JeffreyBenjaminBrown/digraphs-<wbr>with-text/blob/<wbr>e5afd39b950752ccb65997b89ab625<wbr>d859299b4a/test/TParse.hs</a><br>
><br>
</span><div class="HOEnZb"><div class="h5">> Jeff Brown | Jeffrey Benjamin Brown<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Jeff Brown | Jeffrey Benjamin Brown</div><div dir="ltr"><a href="https://msu.edu/~brown202/" style="font-size:12.8px" target="_blank">Website</a>   |   <a href="https://www.facebook.com/mejeff.younotjeff" style="font-size:12.8px" target="_blank">Facebook</a>   |   <a href="https://www.linkedin.com/in/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">LinkedIn</a><span style="font-size:12.8px">(spammy, so I often miss messages here)   </span><span style="font-size:12.8px">|</span><span style="font-size:12.8px">   </span><a href="https://github.com/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">Github</a><span style="font-size:12.8px">   </span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>