[erlang-questions] What is the best location to place common type specs?

Philip Clarke send2philip@REDACTED
Tue Jul 10 13:18:06 CEST 2012


Hi,

Some useful suggestions are given in response to this question, but I'd
also like to know if it is ok to define a spec in a .hrl file and use the
record in multiple modules.
This is how I have been doing it:

In the .hrl file:
----------------------------
-record(my_record, {
        a = 1 :: integer() }).

-type(my_record() :: #my_record{}).

In the .erl file:
-----------------------------
-module(spec_test).
-include("spec_test.hrl").
-export([start/0]).

-spec(start() -> {ok, MyRecord :: my_record()}).
start() ->
    MyRecord = #my_record{},
    {ok, MyRecord}.


This certainly compiles, but I am not up to speed with tools like dialyzer
to verify that this works.
But this approach is correct, or ?

Philip

On Fri, Jul 6, 2012 at 10:08 PM, Max Bourinov <bourinov@REDACTED> wrote:

> Hi Sergey,
>
> Dedicated module that holds types is your friend.
>
> Sent from my iPhone
>
> On 05.07.2012, at 16:07, Zhemzhitsky Sergey <Sergey_Zhemzhitsky@REDACTED>
> wrote:
>
>  Hi guys,
>
>
>
> I have multiple .hrl files with multiple records. I’d like to define
> separate types for these records and their fields.
>
> These records will be used across multiple modules, and I’m wondering
> whether it is legal to define type specs in the hrl files?
>
> Or would it be better to have a separate module with exported common type
> specs?
>
>
>
>
>
> Best Regards,
>
> Sergey
>
>
>
> _______________________________________________________
>
>
>
> The information contained in this message may be privileged and conf
> idential and protected from disclosure. If you are not the original
> intended recipient, you are hereby notified that any review,
> retransmission, dissemination, or other use of, or taking of any action in
> reliance upon, this information is prohibited. If you have received this
> communication in error, please notify the sender immediately by replying to
> this message and delete it from your computer. Thank you for your
> cooperation. Troika Dialog, Russia.
>
> If you need assistance please contact our Contact Center (+7495) 258 0500or go to
> www.troika.ru/eng/Contacts/system.wbp
>
>
>
> _______________________________________________
>
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120710/3f59faad/attachment.htm>


More information about the erlang-questions mailing list