[erlang-questions] Funargs: Ruby-like blocks for Erlang

Tristan Sloughter tristan.sloughter@REDACTED
Fri Jul 22 01:47:27 CEST 2011


Yes, I said it was a poor example :)

On Thu, Jul 21, 2011 at 6:28 PM, Richard O'Keefe <ok@REDACTED> wrote:

>
> On 22/07/2011, at 8:01 AM, Tristan Sloughter wrote:
>
> > 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'.
> >
> > In Erlang I'd do:
> >
> > -spec area_of_circles(record(circle)) -> [float()]
> > area_of_circles(Circles) ->
> >   lists:map(fun(C) ->
> >                               math:pi() * math:pow(C#circle.radius, 2)
> >                 end, Circles).
> >
> Wouldn't you write
>
> area_of_circles(Circles) ->
>        [math:pi()*math:pow(C#circle.radius, 2) || C <- Circles].
>
> > While in Haskell:
> >
> > area_of_circles :: [Shape] -> [Float]
> > area_of_circles circles =
> >   L.map (area_of_circle) circles
> >   where
> >     area_of_circle (Circle radius) = pi * radius^2
>
> Wouldn't you write
>
> area_of_circles circles = [pi*r^2 | Circle r <- circles]
>
> The problem isn't a lack of 'let' and 'where'.
> That's solved just by making names distinct.
> The problem is that normal function definitions don't nest;
> while you can do
>
> area_of_circles(Cs) ->
>    Area = fun (C) -> math:pi()*math:pow(C#Circle.radius, 2) end,
>    lists:map(Area, Cs).
>
> you still have to use a 'fun' to do it.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110721/495225a9/attachment.htm>


More information about the erlang-questions mailing list