[erlang-questions] type specification

Kostis Sagonas kostis@REDACTED
Fri Jul 2 18:41:31 CEST 2010


Serge Aleynikov wrote:
> Can user-defined type specification be imported from or referenced to 
> another module?
> 
> E.g. if I have a function that returns date/time value in the same 
> format as calendar:now_to_local_time/1 whose type t_datetime1970() is 
> defined in the calendar module, what would the -spec of my function be:
> 
> -spec local_time() -> ???
> local_time() ->
>     calendar:now_to_local_time(now()).

If the type is exported (cf. the new -export_type attribute) then what 
you want to write is as simple as:

   -spec local_time() -> calendar:t_datetime1970().

In this particular case, the t_datetime1970() is not exported, so you 
either need to clone it in your module or send a request to the module's 
maintainer to export this type.

Kostis

PS. Btw, I've just checked the 'calendar' manual page and the only types
     that it mentions there are date() and time(), which are also not
     exported by the module (and actually have slightly different names
     t_date() and t_time()).  IMO, they should be renamed and exported.
     It's not so clear to me whether datetime1970() should also be in the
     same category.


More information about the erlang-questions mailing list