<br><div class="gmail_quote">On Wed, Mar 18, 2009 at 12:49 PM, Tom.Amundsen <span dir="ltr">&lt;<a href="mailto:tomamundsen@gmail.com">tomamundsen@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi All,<br>
<br>
I am new to Haskell. I just started reading &quot;Real World Haskell&quot; a few days<br>
ago, so I apologize for being such a noob.<br>
<br>
But, I am curious why I see a lot of code where people do pattern matching<br>
via multiple function declarations instead of using the case ... of ...<br>
construct? For example:<br>
<br>
[code]<br>
foldl&#39; _    zero []     = zero<br>
foldl&#39; step zero (x:xs) =<br>
      let new = step zero x<br>
      in  new `seq` foldl&#39; step new xs<br>
[/code]<br>
<br>
instead of this, which I prefer:<br>
<br>
[code]<br>
foldl&#39; f acc xs = case xs of<br>
                            [] -&gt; acc<br>
                            (x:xs) -&gt; let new = f acc x<br>
                                          in  new `seq` foldl&#39; f new xs<br>
[/code]<br></blockquote></div><br>This is just my opinion, but pure functions are often compared to mathematical functions because they&#39;re similar in the way that neither depend on outside elements, only the inputs.  Consider a mathematical &quot;piecewise function&quot; (<a href="http://en.wikipedia.org/wiki/Piecewise_function">http://en.wikipedia.org/wiki/Piecewise_function</a>).  These are typically defined as:<br>
<br>f(x) = (*definition 1*)   if condition1<br>f(x) = (*definition 2*)   if condition2<br>etc...<br><br>(Normally written with a large curly brace, but the idea is still the same).  To me the notation here matches up nicely with the way of separating cases by defining them as multiple functions in Haskell because the choice of notation itself emphasizes that the function can be split into multiple completely separate computations depending on the format of the input.<br>
<br><br>