Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Is it possible to get a 'simpler' but equivalent representation? Of course, this is called parsing, and is done by compilers, interpreters, etc.</p> <p>90% of the time, all you need to remember is how <code>$</code> , <code>.</code> and function application <code>f x</code> work together. This is because <code>$</code> and function application are really simple - they bind the loosest and tightest respectively - they are like addition and the exponent in <a href="http://en.wikipedia.org/wiki/BODMAS#Mnemonics" rel="nofollow">bodmas</a>.</p> <p>From your example</p> <pre><code>e f $ g . h i . j </code></pre> <p>the function applications bind first, so we have</p> <pre><code>(e f) $ g . (h i) . j </code></pre> <p>Function application is left associative so</p> <pre><code>f g h ==&gt; ((f g) h) </code></pre> <p>You may have to google currying to understand why the above can be used like <code>foo(a, b)</code> in other languages.</p> <p>In the next step do everything in the middle - I just use brackets or a table to remember this bit, it's usually straightforward. For example there are several operators like <code>&gt;&gt;</code> and <code>&gt;&gt;=</code> that are used at the same time when you are working with monads. I just add brackets when ghc complains.</p> <p>So no we have</p> <pre><code>(e f) $ (g . ((h i) . j)) </code></pre> <p>The order of the brackets doesn't matter as <a href="http://en.wikipedia.org/wiki/Function_composition" rel="nofollow">function composition</a> is associative, however Haskell makes it right associative.</p> <p>So then we have</p> <pre><code>((e f) (g . ((h i) . j))) </code></pre> <p>The above (simple) example demonstrates why those operators exist in the first place.</p>
 

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