[erlang-questions] spec declaration for single list parameter with fixed size
Michael Richter
ttmrichter@REDACTED
Sun Jul 3 11:58:34 CEST 2011
On 3 July 2011 16:10, Roberto Ostinelli <roberto@REDACTED> wrote:
> a very stupid spec declaration question. how can you declare the specs of a
> function which has a single list with multiple arguments?
>
For instance, consider this function:
>
> myfun([One, Two]) ->
>
> these two following declarations do obviously not work:
> -spec myfun([One::string(), Two::integer()]) ->
> -spec myfun(list(One::string(), Two::integer())) ->
>
> the proper way seems to be:
> -spec myfun([string() | integer()]) ->
>
> however i feel this to be very misleading, as the specs do not show the
> order nor the fixed length of the parameter list.
>
If you have a fixed length and format, it strikes me that a list isn't the
data structure you want given that a list is by definition variable-length.
Is there a reason you're not using a tuple instead of that list? Something
like this?:
myfun({One, Two}) -> ...
--
"Perhaps people don't believe this, but throughout all of the discussions of
entering China our focus has really been what's best for the Chinese people.
It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110703/77f3d38f/attachment.htm>
More information about the erlang-questions
mailing list