[erlang-questions] Intel Quad CPUs
Tobias Lindahl
tobias.lindahl@REDACTED
Fri Sep 7 09:30:54 CEST 2007
Damien Morton wrote:
> Allow me to apologise in advance for my ignorance, but why do edoc type
> specifications look like function calls?
I am not sure if I misunderstand your question, but as others have
already explained, the parenthesis that make the types look like
function calls are necessary to distinguish between types and singleton
atoms.
The notation of a type with an atom followed by the closed parenthesis
represents a set of terms. The type integer() is the infinite set of all
possible integers. The type integer is the singleton type that only
consists of the atom 'integer'. In the same way the type atom() is the
infinite set consisting of all possible atoms, while the type atom is
the type consisting only of the atom 'integer'.
Consider the function
f(X) when is_atom(X) -> {atom, X};
f(X) when is_integer(X) -> {integer, X}.
This function has the type
(atom()|integer())-> {atom, atom()}|{integer, integer()}
Hope this sheds more light on the syntax with closed parenthesis. If you
are really asking something else, then please try to specify your
question more.
Best,
Tobias
>
> On 9/6/2007 9:47 PM, Bob Ippolito wrote:
>> That's what edoc type specifications look like...
>>
>> On 9/6/07, Damien Morton <dmorton@REDACTED> wrote:
>>
>>> Why does the integer type look like a function call?
>>>
>>> On 9/6/2007 5:16 PM, David Mercer wrote:
>>>
>>>> On Thursday, September 06, 2007, Tony Finch wrote:
>>>>
>>>>
>>>>> What is the reason for the trailing ()s? It would be nice if the syntax
>>>>> had less redundant visual noise.
>>>>>
>>>>>
>>>> So it can tell the difference between an integer and the atom 'integer'?
>>>>
>>>> Cheers,
>>>>
>>>> David
>>>>
>>>> -----Original Message-----
>>>> From: erlang-questions-bounces@REDACTED
>>>> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of
>>>> Sent: 14:00
>>>> To: Kostis Sagonas
>>>> Cc: Erlang
>>>> Subject: Re: [erlang-questions] Intel Quad CPUs
>>>>
>>>> On Tue, 4 Sep 2007, Kostis Sagonas wrote:
>>>>
>>>>
>>>>> In the new language you would write (or preferably change the above edoc
>>>>> comment to be):
>>>>>
>>>>> -spec(foo/2 :: ((integer(), float()) -> atom())).
>>>>>
>>>>>
>>>> What is the reason for the trailing ()s? It would be nice if the syntax
>>>> had less redundant visual noise.
>>>>
>>>> Tony.
>>>>
>>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list