Yes, I said it was a poor example :)<br><br><div class="gmail_quote">On Thu, Jul 21, 2011 at 6:28 PM, Richard O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On 22/07/2011, at 8:01 AM, Tristan Sloughter wrote:<br>
<br>
> A reason I end up with far more anonymous functions in my Erlang than Haskell code (and end up with longer functions in Erlang) is the lack of 'let' and 'where'.<br>
><br>
> In Erlang I'd do:<br>
><br>
> -spec area_of_circles(record(circle)) -> [float()]<br>
> area_of_circles(Circles) -><br>
>   lists:map(fun(C) -><br>
>                               math:pi() * math:pow(C#circle.radius, 2)<br>
>                 end, Circles).<br>
><br>
</div>Wouldn't you write<br>
<br>
area_of_circles(Circles) -><br>
        [math:pi()*math:pow(C#circle.radius, 2) || C <- Circles].<br>
<div class="im"><br>
> While in Haskell:<br>
><br>
> area_of_circles :: [Shape] -> [Float]<br>
> area_of_circles circles =<br>
>   L.map (area_of_circle) circles<br>
>   where<br>
>     area_of_circle (Circle radius) = pi * radius^2<br>
<br>
</div>Wouldn't you write<br>
<br>
area_of_circles circles = [pi*r^2 | Circle r <- circles]<br>
<br>
The problem isn't a lack of 'let' and 'where'.<br>
That's solved just by making names distinct.<br>
The problem is that normal function definitions don't nest;<br>
while you can do<br>
<br>
area_of_circles(Cs) -><br>
    Area = fun (C) -> math:pi()*math:pow(C#Circle.radius, 2) end,<br>
    lists:map(Area, Cs).<br>
<br>
you still have to use a 'fun' to do it.<br>
<br>
</blockquote></div><br>