Erlang Mailing Lists

Author Message

<  Erlang  ~  Dialyzer and parameterized modules

elbrujohalcon
Posted: Thu Sep 30, 2010 2:59 pm Reply with quote
Joined: 08 Mar 2010 Posts: 2 Location: Monte Castro, Buenos Aires, Argentina
I know that since v2.2.0, dialyzer has support for parameterized modules, but somehow it's not working for me.
Lets say that, for some unknown reason (o_O), I want a parameterized module for atom queues.

I write this tiny parameterized module then:

Code:
-module(atom_queue, [Queue]).

-export([push/1, pop/0]).

pop() -> case Queue of
           [] -> {undefined, atom_queue:new([])};
           [X|Rest] -> {X, atom_queue:new(Rest)}
         end.

push(X) -> atom_queue:new(lists:reverse([X|Queue])).


If I run dialyzer on it, no warnings are reported. But it has no specs and I like to compile my code with warn_missing_spec. The compiler says that the specs for pop/0 and push/1 are missing. So, I add the specs...

Code:
-module(atom_queue, [Queue]).

-export([push/1, pop/0]).

-spec pop() -> {undefined | atom(), {?MODULE, [atom()]}}.
pop() -> case Queue of
           [] -> {undefined, atom_queue:new([])};
           [X|Rest] -> {X, atom_queue:new(Rest)}
         end.

-spec push(atom()) -> {?MODULE, [atom()]}.
push(X) -> atom_queue:new(lists:reverse([X|Queue])).


Compiler is not complaining anymore, which is great. But when I try to dialyze the module, I get:
Quote:
Contract for function that does not exist: atom_queue:pop/0
Contract for function that does not exist: atom_queue:push/1


I change the specs to satisfy dialyzer, like this:
Code:
-module(atom_queue, [Queue]).

-export([push/1, pop/0]).

-spec pop({?MODULE, [atom()]}) -> {undefined | atom(), {?MODULE, [atom()]}}.
pop() -> case Queue of
           [] -> {undefined, atom_queue:new([])};
           [X|Rest] -> {X, atom_queue:new(Rest)}
         end.

-spec push(atom(), {?MODULE, [atom()]}) -> {?MODULE, [atom()]}.
push(X) -> atom_queue:new(lists:reverse([X|Queue])).


But, of course, I can't compile that code:
Quote:
spec for undefined function atom_queue:pop/1
spec for undefined function atom_queue:push/2


So, the question is basically: How can I write a parameterized module with specs that satisfies both dialyzer and erlc at the same time?
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
wuji
Posted: Sat Sep 08, 2012 1:36 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
is when Denniston knew what he had to do."I asked asked cheap designer *beep* asked the swimmers, 'If I apply for the position, would
all stay?'" Denniston said.The team agreed."I love swimming under Dave, Dave, replica designer *beep* Dave, and I think he is a good fit," said
Kamber, a member of the Paralympics swimming team. "He understands understands [h2]cheap jordans[/h2] understands each of our training needs."Recently, Denniston was announced as
head coach of the 2012 Paralympic Resident Swim team in in [h4]cheap polo shirts[/h4] in Colorado Springs -- the same position his mentor Flowers
before him.Denniston said that if he had to sum up up [h2]replica designer *beep*[/h2] up his experiences since his 2005 accident in a single
it would be "blessed.""I feel blessed every day," he said. said. [h4]cheap jordans[/h4] said. "I get to coach some of the greatest athletes
View user's profile Send private message
dongdongwu
Posted: Wed Sep 19, 2012 8:26 am Reply with quote
User Joined: 19 Sep 2012 Posts: 236
Girls would refuse to even leave their replicas behind. specifically when the product beats the complete meaning of the Christian Louboutin men outlet; in conditions of good quality and detailing.If Cinderella was residing in your twenty primary century as opposed to the aged a single then there would not be any 'Happy actually after'. properly appears like girls nowadays are as well fond of the strong;Christian Louboutin Men Shoes to leave them in your center of nowhere.Christian Louboutin for men Shoes would arrive true handy being a excellent handbag using the glimpse and really feel belonging to the authentic but at a very much lesser price tag adding as very much as types picture in your process.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum