title: Define a closure variable in buckle script
body: <p>I'm trying to convert the following ES6 script to bucklescript and I cannot for the life of me figure out how to create a "closure" in bucklescript</p>
  
  <pre class="lang-js prettyprint-override"><code>    import {Socket, Presence} from "phoenix"
  
      let socket = new Socket("/socket", {
        params: {user_id: window.location.search.split("=")[1]}
      })
  
      let channel = socket.channel("room:lobby", {})
      let presence = new Presence(channel)
  
      function renderOnlineUsers(presence) {
        let response = ""
  
        presence.list((id, {metas: [first, ...rest]}) =&gt; {
          let count = rest.length + 1
          response += `&lt;br&gt;${id} (count: ${count})&lt;/br&gt;`
        })
  
        document.querySelector("main[role=main]").innerHTML = response
      }
  
      socket.connect()
  
      presence.onSync(() =&gt; renderOnlineUsers(presence))
  
      channel.join()
  </code></pre>
  
  <p>the part I cant figure out specifically is <code>let response = ""</code> (or var in this case as bucklescript always uses <code>var</code>s):</p>
  
  <pre class="lang-js prettyprint-override"><code>    function renderOnlineUsers(presence) {
        let response = ""
  
        presence.list((id, {metas: [first, ...rest]}) =&gt; {
          let count = rest.length + 1
          response += `&lt;br&gt;${id} (count: ${count})&lt;/br&gt;`
        })
  
        document.querySelector("main[role=main]").innerHTML = response
      }
  </code></pre>
  
  <p>the closest I've gotten so far excludes the <code>result</code> declaration</p>
  
  <pre class="lang-ml prettyprint-override"><code>...
  ...
  
  let onPresenceSync ev =
    let result = "" in
      let listFunc = [%raw begin
          {|
            (id, {metas: [first, ...rest]}) =&gt; {
              let count = rest.length + 1
              result += `${id} (count: ${count})\n`
            }
          |}
        end
      ] in
        let _ =
          presence |. listPresence (listFunc) in
            [%raw {| console.log(result) |} ]
  ...
  ...
  </code></pre>
  
  <p>compiles to:</p>
  
  <pre class="lang-js prettyprint-override"><code>function onPresenceSync(ev) {
    var listFunc = (
            (id, {metas: [first, ...rest]}) =&gt; {
              let count = rest.length + 1
              result += `${id} (count: ${count})\n`
            }
          );
    presence.list(listFunc);
    return ( console.log(result) );
  }
  </code></pre>