Erlang Mailing Lists

Author Message

<  Erlang  ~  Dialyzer maybe_immproper_list usage and an internal error

Bill M.
Posted: Mon Nov 03, 2008 1:40 am Reply with quote
User Joined: 06 Jun 2008 Posts: 24 Location: New York
Please recall that the documentation on the function contracts using the -spec() statement in the Erlang Enhancement Proposal 8, eep-0008, at: http://www.erlang.org/svn/projects/eeps/trunk/eep-0008.txt?revision=37&view=markup. I'm using lists with homogeneously typed elements, but list types are a little tricky to get correct in the dialyzer. There is a notion of an improper_list and a maybe_improper_list that I don't fully understand. The dialyzer suggested that I use a maybe_improper_list() for a list parameter, so I did it, however, I also wanted to specify the list element type for stricter static checking.

So here is an example:
Code:

-spec(compute_generator/3 :: (Q :: pos_integer(), P :: maybe_improper_list(pos_integer(), pos_integer()), T :: non_neg_integer())-> pos_integer()).
compute_generator( Q, P, T ) when (is_integer(Q) and is_list(P) and is_integer(T)) andalso ((Q > 0) and (T >= 0)) ->


As far as I can tell, this seems permitted as per the linked eep-0008, but the dialyzer installed on my system cannot handle it, and hits what appears to be an internal error. My system is OpenSuse Linux 11.0 (with current patches), the Erlang version is (from the Redhat Package Manager, RPM, also used by OpenSUSE) erlang-R12B3-22.1. The dialyzer reports:
Code:

dialyzer --plt dialyzer.plt -Wunmatched_returns -Werror_handling -Wunderspecs -Woverspecs -Wspecdiffs  -r . | tee dialyzer.log
  Checking whether the PLT dialyzer.plt is up-to-date... yes
  Proceeding with analysis...
=ERROR REPORT==== 2-Nov-2008::19:42:55 ===
Error in process <0.29.0> with exit value: {{badmatch,false},[{erl_types,t_maybe_improper_list,2},{erl_types,'-t_from_form/3-lc$^0/1-3-',3},{erl_types,t_from_form,3},{dialyzer_contracts,contract_from_form,4},{dialyzer_contracts,contract_from_form,2},{dialyzer_utils...


Analysis failed with error: {{badmatch,false},
 [{erl_types,t_maybe_improper_list,2},
  {erl_types,'-t_from_form/3-lc$^0/1-3-',3},
  {erl_types,t_from_form,3},
  {dialyzer_contracts,contract_from_form,4},
  {dialyzer_contracts,contract_from_form,2},
  {dialyzer_utils,get_spec_info,5},
  {dialyzer_utils,get_spec_info,...},
  {dialyzer_analysis_callgraph,...}]}
Last messages in log cache: ["Reading files and computing callgraph... "]

dialyzer: Internal problems were encountered in the analysis.

Any idea what caused this, and who to contact? For now I can work around this by removing the element type qualifiers, but this is not an ideal solution.
View user's profile Send private message
lestat
Posted: Tue Nov 04, 2008 2:36 pm Reply with quote
User Joined: 07 Jun 2007 Posts: 14
Bill M. wrote:
Please recall that the documentation on the function contracts using the -spec() statement in the Erlang Enhancement Proposal 8, eep-0008, at: http://www.erlang.org/svn/projects/eeps/trunk/eep-0008.txt?revision=37&view=markup. I'm using lists with homogeneously typed elements, but list types are a little tricky to get correct in the dialyzer. There is a notion of an improper_list and a maybe_improper_list that I don't fully understand. The dialyzer suggested that I use a maybe_improper_list() for a list parameter, so I did it, however, I also wanted to specify the list element type for stricter static checking.

So here is an example:
Code:

-spec(compute_generator/3 :: (Q :: pos_integer(), P :: maybe_improper_list(pos_integer(), pos_integer()), T :: non_neg_integer())-> pos_integer()).
compute_generator( Q, P, T ) when (is_integer(Q) and is_list(P) and is_integer(T)) andalso ((Q > 0) and (T >= 0)) ->


As far as I can tell, this seems permitted as per the linked eep-0008, but the dialyzer installed on my system cannot handle it, and hits what appears to be an internal error. My system is OpenSuse Linux 11.0 (with current patches), the Erlang version is (from the Redhat Package Manager, RPM, also used by OpenSUSE) erlang-R12B3-22.1. The dialyzer reports:
Code:

dialyzer --plt dialyzer.plt -Wunmatched_returns -Werror_handling -Wunderspecs -Woverspecs -Wspecdiffs  -r . | tee dialyzer.log
  Checking whether the PLT dialyzer.plt is up-to-date... yes
  Proceeding with analysis...
=ERROR REPORT==== 2-Nov-2008::19:42:55 ===
Error in process <0.29.0> with exit value: {{badmatch,false},[{erl_types,t_maybe_improper_list,2},{erl_types,'-t_from_form/3-lc$^0/1-3-',3},{erl_types,t_from_form,3},{dialyzer_contracts,contract_from_form,4},{dialyzer_contracts,contract_from_form,2},{dialyzer_utils...


Analysis failed with error: {{badmatch,false},
 [{erl_types,t_maybe_improper_list,2},
  {erl_types,'-t_from_form/3-lc$^0/1-3-',3},
  {erl_types,t_from_form,3},
  {dialyzer_contracts,contract_from_form,4},
  {dialyzer_contracts,contract_from_form,2},
  {dialyzer_utils,get_spec_info,5},
  {dialyzer_utils,get_spec_info,...},
  {dialyzer_analysis_callgraph,...}]}
Last messages in log cache: ["Reading files and computing callgraph... "]

dialyzer: Internal problems were encountered in the analysis.

Any idea what caused this, and who to contact? For now I can work around this by removing the element type qualifiers, but this is not an ideal solution.


This seems like a genuine bug to me. You are right it is proper usage of the maybe_improper_list. It is not necessary right, but it still shouldn't crash on you. I recommend erlang-questions mailing list as the maintainers/creators of dialyzer read it.

The idea of maybe_improper_list is fairly simple:
During pattern matching there are two matches one usually use on lists:
- [] (empty list)
- [X | Xs] (a non empty list)

If the list is a proper list then Xs is a list as well, so the last element of a proper list is always the empty list.
Try writing this into the shell and see what you get: [1 | [2 | [3 | []]]].

So what does maybe_improper_list(T1, T2) stand for:
It specifies that all the elements in the list are of T1 type and the end of the list is either the [] or T2 type value (hence maybe).

What you have to keep in mind is [1,2,3,alma] is a proper list. It is a syntactic sugar for [1 | [2 | [3 | [alma | [] ] ] ] ].

On the other hand [1,2,3 | alma] is an improper list. Which is a syntactic sugar for [1 | [ 2 | [ 3 | alma ] ] ].

So if your list is always a proper list try writing list(pos_integer()) and see what dialyzer says. If this spec does not hold there might be an error/bug in the list generation.
View user's profile Send private message
Bill M.
Posted: Thu Nov 06, 2008 3:59 am Reply with quote
User Joined: 06 Jun 2008 Posts: 24 Location: New York
Thanks Lestat,

Your hints are quite helpful. Some people may think of famous fictional vampires when they see your name, but to me, your name makes me think you might know something about code refactoring technology. If you are indeed the Lestat I'm thinking of, and you are still active in Erlang refactoring tools (or have other interesting developments/research you can talk about) I'd be interesting trying these things and would like to hear about it.

I appreciate your tutorial on improper_list and maybe_improper_list, that is quite helpful. I'll need to look more carefully at my list generation code and see whether I have an error there, although I tried to make proper lists, there is always the possibility of an error.

Regarding the glitch that I saw, I plan on submitting a proper bug report on the lists, I may directly contact the authors if the mailing lists don't activate for me in a reasonable period. I have not yet gotten my registration to take for the mailing lists (I'm not sure if the admins/moderators have a backlog or if my registration attempt failed, it would have been nice to get an acknowledgment mail indicating that a registration attempt was initiated, so perhaps I made a cockpit error trying for both erlang-bugs@erlang.org and erlang-questions@erlang.org).

Thanks again:

Bill M.
View user's profile Send private message
pergu
Posted: Thu Nov 06, 2008 5:46 pm Reply with quote
User Joined: 01 Mar 2005 Posts: 37 Location: Uppsala Sweden
I had a quick look at the code and the problem seems to be that maybe_improper_list expects the second type to include nil. That is to make it work as you want it to you have to write:

maybe_inproper_list(int(), int() | [])

This is still a bug however since dialyzer shouldn't crash, and dialyzer should probably add [] to the second type automatically.

Per
View user's profile Send private message
lestat
Posted: Fri Nov 07, 2008 2:28 pm Reply with quote
User Joined: 07 Jun 2007 Posts: 14
Well I'm not active in the RefactorErl project right now as I joined the working class. Smile
I work for Erlang Training & Consulting.

I still see how the development go on RefactorErl so expect major improvements (for example layout preserving refactorings). As far as I know the group is going to present on EUC.

I have a few ideas but I didn't have time to get started with them yet, but if you like web development give ErlangWeb a try. I used an earlier version of it in one of my projects and it made the ui development a breeze.

Have we met before somewhere? I'm really bad with names so if you could give me a hint that would be helpful. Smile
View user's profile Send private message
Bill M.
Posted: Sat Nov 08, 2008 4:54 am Reply with quote
User Joined: 06 Jun 2008 Posts: 24 Location: New York
Thanks Pergu:

This is very helpful. I'm still not sure what coding errors (if any) are making the Dialyzer think that I've not properly terminated my lists, I'm trying to track it down still. Thanks for explaining this, I appreciate it. I tried a variant of this (my list should contain pos_integer() elements) and it fixed the crash condition, but the dialyzer says my success type is maybe_improper_list(), not with typed elements.

pergu wrote:
I had a quick look at the code and the problem seems to be that maybe_improper_list expects the second type to include nil. That is to make it work as you want it to you have to write:

maybe_inproper_list(int(), int() | [])

This is still a bug however since dialyzer shouldn't crash, and dialyzer should probably add [] to the second type automatically.

Per
View user's profile Send private message
Bill M.
Posted: Sat Nov 08, 2008 5:19 am Reply with quote
User Joined: 06 Jun 2008 Posts: 24 Location: New York
Hi Lestat:

We probably haven't met, but the forum showed your previous posts, and I noticed some were with your handle on the RefactorErl project, so I thought I'd ask. My surname is sufficiently unique that if I disclose it, I tend to get spammed, so I'll P.M. you. I'm not doing traditional web development, unfortunately it is still a bit too early to talk about what we are doing just yet.

Regards:

Bill
lestat wrote:
Well I'm not active in the RefactorErl project right now as I joined the working class. Smile
I work for Erlang Training & Consulting.

I still see how the development go on RefactorErl so expect major improvements (for example layout preserving refactorings). As far as I know the group is going to present on EUC.

I have a few ideas but I didn't have time to get started with them yet, but if you like web development give ErlangWeb a try. I used an earlier version of it in one of my projects and it made the ui development a breeze.

Have we met before somewhere? I'm really bad with names so if you could give me a hint that would be helpful. Smile
View user's profile Send private message
wuji
Posted: Fri Aug 24, 2012 8:33 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
a small number of cases -- just 11 -- the the cheap authentic air jordans the parents insisted on continuing intensive care while they prayed
divine intervention and a complete cure, even after being told told [h3]cheap real jordans[/h3] told there was no hope for recovery.Overriding Religious BeliefsSuch scenarios
up all sorts of ethical and legal dilemmas for medical medical cheap Ralph Lauren medical caregivers who must try to balance a parent's wishes
what they think is best for their patient. Caplan says says [h4]knockoff designer *beep*[/h4] says in most cases, they ultimately advocate for the patient."You
to take beliefs into account but you can't let any any [h2]cheap replica *beep*[/h2] any parent for any reason hijack what you as a
View user's profile Send private message
dongdongwu
Posted: Thu Sep 20, 2012 2:14 am Reply with quote
User Joined: 19 Sep 2012 Posts: 236
His good friend Diane said: "Christian Louboutin Men Shoes was a magician, he make shoes is immediately put his female people with legs and advantage. He understands women wanted to do and can make them into beautiful Cinderella." Madonna often in its concert wearing Christian louboutin high heels , and some famous superstar like Angelina jolie, mariah Carey, beyonce Knowles, the famous Japanese singer YaYouMei Hamasaki helps Christian Louboutin Men Shoes set up its powerful position. The youngest customers will count Tom cruise's daughter sully cruz. Louboutin made for only a pair of handmade Christian Louboutin high heel Shoes! Want to be more fashion? Put on Christian Louboutin Outlet !
Candy colors of the chalaza high-heeled shoes with lolita type allure, set full finely gem blue "neon shoes" is to need to use "sexy" to describe. Each pair are worth careful appreciation of lithe and graceful fairy ludaoli, what kind of most let you move?Christian Louboutin Men Shoes that one brush red is always cannot resist the temptation, Christian Louboutin men outlet continue to use the days of high 8cm above slender heel proclaim the sexy and luxuriant. The bowknot on black pointed high-heeled shoes with sharp rivet concomitant, wild python met enchanting color printing grain, It is that pairs of high-heeled shoes lets Carrie more feminine flavour. Like Christian Louboutin for men her word.
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