title: When function should be effectful?
body: <p>When I use FFI to wrap some API (for example DOM API) is there any rule of thumb that could help me to decide whether function should be effectful or not?</p>
  
  <p>Here is an example:</p>
  
  <pre><code>foreign import querySelectorImpl """
      function querySelectorImpl (Nothing) {
        return function (Just) {
          return function (selector) {
            return function (src) {
              return function () {
                var result = src.querySelector(selector);
                return result ? Just(result) : Nothing;
              };
            };
          };
        };
      }
    """ :: forall a e. Maybe a -&gt; (a -&gt; Maybe a) -&gt; String -&gt; Node -&gt; Eff (dom :: DOM | e) (Maybe Node)
  
  querySelector :: forall e. String -&gt; Node -&gt; Eff (dom :: DOM | e) (Maybe Node)
  querySelector = querySelectorImpl Nothing Just
  
  foreign import getTagName """
      function getTagName (n) {
        return function () {
          return n.tagName;
        };
      }
    """ :: forall e. Node -&gt; Eff (dom :: DOM | e) String
  </code></pre>
  
  <p>It feels right for <code>querySelector</code> to be effectful, but I'm not quite sure about <code>getTagName</code></p>
  
  <p><strong>Update:</strong></p>
  
  <p>I understand what a pure function is and that it should not change the state of the program and maybe DOM was a bad example.</p>
  
  <p>I ask this question because in most libraries that wrap existing js libraries pretty much every function is effectful even if it doesn't feels right. So maybe my actual question is - does this effect represent the need in this wrapped js lib or is it there just in case it is stateful inside?</p>