[erlang-questions] Noob question about records

Gordon Guthrie gordon@REDACTED
Sun Apr 26 18:05:00 CEST 2009


Larry wrote:

> Ah, now that's nice code. I'm clearly not thinking in Erlang yet. Is
> there any advantage to learning Haskell or another functional language
> first?

I found going from OO to FP as hard as going from Fortran to C++ -
there is no substitute for slogging it out I'm afraid.

The good news is that after 3 years you will lose your ability to read
OO languages like Ruby...

The bad news is then you will need to build both ends of a website and
the Gates Of Hell will swing open when you load Javascript into an
editor...

Gordon


On Sun, Apr 26, 2009 at 4:06 PM, ljw1001 <ljw1001@REDACTED> wrote:
> Ah, now that's nice code. I'm clearly not thinking in Erlang yet. Is
> there any advantage to learning Haskell or another functional language
> first? I have Joe's book, but I haven't found anything to help me get
> the hang of functional programming specifically for Erlang.
>
> Sent from my iPhone
>
> On Apr 25, 2009, at 10:54 PM, Steve Vinoski <vinoski@REDACTED> wrote:
>
>> On 4/25/09, Larry White <ljw1001@REDACTED> wrote:
>>> -record(money, { currency = usd, amount = 0 }).
>>>
>>> add(Money1, Money2) ->
>>>        #money{currency=Cur1, amount=Amt1} = Money1.
>>>        #money{currency=Cur2, amount=Amt2} = Money2.
>>>        %% TODO: Check to see that the currencies are the same and
>>> throw
>>> exception if not
>>>        Total = Amt1 + Amt2.
>>>        #money{currency=Cur1,amount=
>>> Total}.
>>
>> Note that you don't need to check the currencies and throw an
>> exception in the manner your comment suggests. Do this instead:
>>
>> add(#money{currency = C, amount = Amt1}, #money{currency = C, amount
>> = Amt2}) ->
>>    #money{currency = C, amount = Amt1 + Amt2}.
>>
>> Let pattern matching do the work for you.
>>
>> --steve
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list