Thanks Tim! I got it! I have never declared a function before in a let ... in statement, I always do it in a where after I call it...<br><br><div class="gmail_quote">On Fri, Oct 30, 2009 at 3:03 PM, Tim Wawrzynczak <span dir="ltr">&lt;<a href="mailto:inforichland@gmail.com">inforichland@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;">Hector,<br><br>That line is declaring a function named &#39;f&#39; of two arguments: one is &#39;w&#39;, and the other is a tuple.  The tuple&#39;s fst is &#39;inputs&#39;, and its snd is &#39;expected.&#39;  This function (f) is used in the next line, in the declaration of the list &#39;newWeights,&#39; which uses f as the function which does the fold over the allInputs list.<br>


<br>Cheers,<br><font color="#888888"> - Tim<br><br></font><div class="gmail_quote"><div><div></div><div class="h5">On Thu, Oct 29, 2009 at 2:27 PM, Hector Guilarte <span dir="ltr">&lt;<a href="mailto:hectorg87@gmail.com" target="_blank">hectorg87@gmail.com</a>&gt;</span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
Hi cafe,<br><br>I&#39;m trying to implement a Perceptron in Haskell and I found one in: <a href="http://jpmoresmau.blogspot.com/2007/05/perceptron-in-haskell.html" target="_blank">http://jpmoresmau.blogspot.com/2007/05/perceptron-in-haskell.html</a> (Thanks JP Moresmau) but there is one line I don&#39;t understand, I was wondering if someone could explain it to me. I know the theory behind a perceptron, my question is more about the Haskell syntax in that line I don&#39;t understand.<br>




<br>epoch :: [([Float],Float)] -&gt; -- ^ Test Cases and Expected Values for each test case<br>                   [Float] -&gt; -- ^ weights<br>              ([Float],Float) -- ^ New weights, delta<br>epoch allInputs weights=<br>




    let<br>        f w (inputs,expected) = step inputs w expected -- I don&#39;t understand this line<br>        newWeights = foldl f weights allInputs -- Neither this one<br>        delta = (foldl (+) 0 (map abs (zipWith (-) newWeights weights))) / (fromIntegral $ length weights)<br>




    in (newWeights,delta)<br><br>What is f and what is w? I really don&#39;t get it, Is like it is defining a function f which calls step unziping the input, taking one of the elements from the fst and it&#39;s corresponding snd and invoking step with that, along with w (which seems to be a list according to step&#39;s signature but I don&#39;t know where it comes from), and then applying fold to the weights and all the Inputs using that f function... But I don&#39;t get it!<br>




<br>Maybe if someone could rewrite that redefining f as an separate function and calling fold with that function I&#39;ll get it.<br><br>The input for epoch would be something like this:<br>epoch [([0,0],0),([0,1],0),([1,0],0),([1,1],1)] [-0,413,0.135]<br>




<br>and the output for that examples is:<br>([0.0,412.9],3.333537e-2)<br><br><br>Thanks a lot,<br><font color="#888888"><br>Hector Guilarte<br>
</font><br></div></div><div class="im">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></div></blockquote></div><br>
</blockquote></div><br>