<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>I haven't used unboxed tuples enough to perhaps feel the pain,
      but on paper the current design makes sense to me. The laziness of
      the binding is suppose to have to do with the runtime rep of the
      binding itself, not any enclosing pattern.<br>
    </p>
    <div class="moz-cite-prefix">For example take<br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">    {-# LANGUAGE ScopedTypeVariables
      #-}</div>
    <div class="moz-cite-prefix">    {-# LANGUAGE MagicHash #-}</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">    import GHC.Base</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">    data Foo = Foo Int# Int#</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">    main = pure ()</div>
    <div class="moz-cite-prefix">        where Foo x y = Foo undefined
      undefined</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">This program will fail even though x
      and y are unused.</div>
    <p>While this principle may not match how this stuff is used in
      practice, the alternative of making the strictness of the bindings
      depend on more than their runtime reps seems less-local / more
      ad-hoc to me.</p>
    <p>John<br>
    </p>
    <div class="moz-cite-prefix">On 8/31/20 10:34 AM, Spiwack, Arnaud
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAH6fHQ=Uj5d2JpV3hxZgAdowZ2xZKCjnGQ0j30K4iJD3MfqifQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div class="markdown-here-wrapper" style="">
          <p style="margin:0px 0px 1.2em!important">I’ve been pointed to
            <a
              href="https://github.com/ghc-proposals/ghc-proposals/pull/35"
              moz-do-not-send="true">https://github.com/ghc-proposals/ghc-proposals/pull/35</a>
            where this was debated a few years ago. With much of the
            same arguments as today.</p>
          <p style="margin:0px 0px 1.2em!important">Simon Marlow said</p>
          <div class="markdown-here-exclude">
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div>making an unboxed tuple binding lazy by default seems
                to be intuitively the wrong choice. I guarantee I would
                get tripped up by this! Giving unboxed tuples an
                implicit bang seems reasonable to me.</div>
            </blockquote>
          </div>
          <p style="margin:0px 0px 1.2em!important">I can share that I
            got tripped by it. And so were other members of my team.</p>
          <p style="margin:0px 0px 1.2em!important">That being said,
            Richard seemed to feel rather strongly about this one.
            Richard, do you still agree with your then position that <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">let (#x, y#) = …</code>
            being a lazy pattern (hence implicitly boxes the pair) is
            the right semantics?</p>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, Aug 28, 2020 at 8:26
          PM chessai <<a href="mailto:chessai1996@gmail.com"
            moz-do-not-send="true">chessai1996@gmail.com</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="auto">Arnaud,
            <div dir="auto"><br>
            </div>
            <div dir="auto">I have dealt with this in the past and find
              the laziness extremely counterintuitive and never wanted.
              Every time I have let-bound an unboxed tuple, I have never
              wanted that boxing to occur. Perhaps there is a good
              reason this is the case but I wish it would change.</div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Fri, Aug 28, 2020,
              08:26 Spiwack, Arnaud <<a
                href="mailto:arnaud.spiwack@tweag.io" target="_blank"
                moz-do-not-send="true">arnaud.spiwack@tweag.io</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div dir="ltr">
                <div>
                  <p style="margin:0px 0px 1.2em">Hi Carter,</p>
                  <p style="margin:0px 0px 1.2em">We are using <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">let !(#x,y#) = …</code>
                    actually. Having the strict behaviour is not
                    particularly difficult. You can even use <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">case … of (#x, y#) ->…</code>
                    directly, it’s not too bad. My complaint, as it
                    were, is solely about the potential for mistakes.</p>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Fri, Aug 28, 2020
                  at 3:20 PM Carter Schonwald <<a
                    href="mailto:carter.schonwald@gmail.com"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">carter.schonwald@gmail.com</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  <div>
                    <div dir="auto">Have you tried using do notation for
                      bindings you want to keep strict, with Eg the
                      identity monad?  That doesn’t address  the design
                      critique but gives you a path forward ? </div>
                  </div>
                  <div dir="auto"><br>
                  </div>
                  <div dir="auto">I do agree that the semantics /
                    default recursivity Of let bindings  can be
                    inappropriate for non recursive code , but would any
                    other non uniform semantics or optimization be safe?</div>
                  <div><br>
                    <div class="gmail_quote">
                      <div dir="ltr" class="gmail_attr">On Fri, Aug 28,
                        2020 at 9:05 AM Spiwack, Arnaud <<a
                          href="mailto:arnaud.spiwack@tweag.io"
                          rel="noreferrer" target="_blank"
                          moz-do-not-send="true">arnaud.spiwack@tweag.io</a>>
                        wrote:<br>
                      </div>
                      <blockquote class="gmail_quote" style="margin:0px
                        0px 0px 0.8ex;border-left:1px solid
                        rgb(204,204,204);padding-left:1ex">
                        <div dir="ltr">
                          <div>
                            <p style="margin:0px 0px 1.2em">Dear all,</p>
                            <br>
                            <br>
                            <p style="margin:0px 0px 1.2em">I discovered
                              the hard way, yesterday, that lazy let
                              pattern<br>
                              matching is allowed on unboxed tuples. And
                              that it implicitly reboxes<br>
                              the pattern.</p>
                            <br>
                            <br>
                            <p style="margin:0px 0px 1.2em">Here is how
                              the manual describes it, from the <a
href="https://downloads.haskell.org/ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-UnboxedTuples"
                                rel="noreferrer" target="_blank"
                                moz-do-not-send="true">relevant section</a>:</p>
                            <br>
                            <br>
                            <blockquote style="margin:1.2em
                              0px;border-left:4px solid
                              rgb(221,221,221);padding:0px
                              1em;color:rgb(119,119,119);quotes:none"><br>
                              <br>
                              <p style="margin:0px 0px 1.2em">You can
                                have an unboxed tuple in a pattern
                                binding, thus</p>
                              <br>
                              <br>
                              <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);display:block;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248) none repeat scroll 0% 0%"><span style="color:rgb(153,0,0);font-weight:bold">f</span> x = <span style="color:rgb(51,51,51);font-weight:bold">let</span> (# p,q #) = h x <span style="color:rgb(51,51,51);font-weight:bold">in</span> ..body..

</code></pre>
                              <br>
                              <br>
                              <p style="margin:0px 0px 1.2em">If the
                                types of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">p</code>
                                and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">q</code>
                                are not unboxed, the resulting binding
                                is lazy like any other Haskell pattern
                                binding. The above example desugars like
                                this:</p>
                              <br>
                              <br>
                              <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);display:block;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248) none repeat scroll 0% 0%"><span style="color:rgb(153,0,0);font-weight:bold">f</span> x = <span style="color:rgb(51,51,51);font-weight:bold">let</span> t = <span style="color:rgb(51,51,51);font-weight:bold">case</span> h x <span style="color:rgb(51,51,51);font-weight:bold">of</span> { (# p,q #) -> (p,q) }

          p = fst t

          q = snd t

      <span style="color:rgb(51,51,51);font-weight:bold">in</span> ..body..

</code></pre>
                              <br>
                              <br>
                              <p style="margin:0px 0px 1.2em">Indeed,
                                the bindings can even be recursive.</p>
                              <br>
                              <br>
                            </blockquote>
                            <br>
                            <br>
                            <p style="margin:0px 0px 1.2em">Notice how <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">h x</code>
                              is lazily bound, hence won’t necessarily
                              be run when<br>
                              <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">body</code>
                              is forced. as opposed to if I had written,
                              for instance,</p>
                            <br>
                            <br>
                            <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);display:block;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248) none repeat scroll 0% 0%"><span style="color:rgb(153,0,0);font-weight:bold">let</span> u = hx

<span style="color:rgb(153,0,0);font-weight:bold">in</span> ..body..

</code></pre>
                            <br>
                            <br>
                            <p style="margin:0px 0px 1.2em">My question
                              is: are we happy with this? I did find
                              this extremely<br>
                              surprising. If I’m using unboxed tuples,
                              it’s because I want to<br>
                              guarantee to myself a strict, unboxed
                              behaviour. But a very subtle<br>
                              syntactic detail seems to break this
                              expectation for me. My<br>
                              expectation would be that I would need to
                              explicitly rebox things<br>
                              before they get lazy again.</p>
                            <br>
                            <br>
                            <p style="margin:0px 0px 1.2em">I find that
                              this behaviour invites trouble. But you
                              may disagree. Let<br>
                              me know!</p>
                            <br>
                            <br>
                          </div>
                        </div>
                        <br>
                        <br>
                        _______________________________________________<br>
                        <br>
                        ghc-devs mailing list<br>
                        <br>
                        <a href="mailto:ghc-devs@haskell.org"
                          rel="noreferrer" target="_blank"
                          moz-do-not-send="true">ghc-devs@haskell.org</a><br>
                        <br>
                        <a
                          href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs"
                          rel="noreferrer noreferrer" target="_blank"
                          moz-do-not-send="true">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
                        <br>
                      </blockquote>
                    </div>
                  </div>
                </blockquote>
              </div>
              _______________________________________________<br>
              ghc-devs mailing list<br>
              <a href="mailto:ghc-devs@haskell.org" rel="noreferrer"
                target="_blank" moz-do-not-send="true">ghc-devs@haskell.org</a><br>
              <a
                href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs"
                rel="noreferrer noreferrer" target="_blank"
                moz-do-not-send="true">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
ghc-devs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a>
</pre>
    </blockquote>
  </body>
</html>