[erlang-questions] Dict size in guards

Raphael Korsoski raphael.korsoski@REDACTED
Fri Feb 11 16:29:09 CET 2011


Hi,

To my understanding, Haskell guards are very different from Erlang guards.  Haskell compiles guards to case statements (afaik), while Erlang evaluates them for selection at runtime.

In Haskell we can write:

f x | my_length(x)  > 3 = "longer than 3"
    | otherwise = "shorter than or equal to 3"
    where my_length = λa →  <some function, e.g. length(a)>

which does contain a user-defined non-monadic funtion. 

In GHC it's also possible to do binding within guards, like so:

g x | s ←  my_length(x)
    , s > 3 = "longer than 3"
    | otherwise = "shorter than or equal to 3"
    where my_length = λa →  <some funtion>

Hope that answers something of your question.

BR,
Raphael K  

-----Original Message-----
From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On Behalf Of David Mercer
Sent: den 11 februari 2011 15:35
To: 'Richard O'Keefe'
Cc: 'Erlang Questions'
Subject: RE: [erlang-questions] Dict size in guards

On Thursday, February 10, 2011, Richard O'Keefe wrote:

> Guards cannot and should not call functions.
                ^^^^^^^^^^^^^^

Is the "should not" because of side-effects in Erlang functions?  If Erlang functions were pure, would you remove the "and should not" from your statement?  I realize there may be issues of performance if they are allowed, but that would be up to the programmer, I suppose.  Does Haskell permit user-defined (non-monadic) functions in guards?

Just asking from a language theory point of view, since I know you're an expert in this area.  Thanks, ROK.

Cheers,

DBM


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED



More information about the erlang-questions mailing list