Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:03:42+00:00 2026-06-10T17:03:42+00:00

I am reading with interest the online book " learn you some erlang "

  • 0

I am reading with interest the online book "learn you some erlang" and trying some exercises to check my understanding.

I made some modification on the fifo example, in the chapter Type Specifications and Erlang, trying to define a "typed_fifo(T)" (a fifo where all elements must be of the same type T)

my type specification are:

-type typed_empty_fifo() :: {fifo, [], []}.

-type typed_nonempty_fifo(A) :: {fifo, nonempty_list(A), list(A)} | {fifo, [],nonempty_list(A) }.

-type typed_fifo(A) :: typed_empty_fifo() | typed_nonempty_fifo(A).

and when I use it in the following function spec:

-spec empty (typed_empty_fifo()) -> true;

  (typed_nonempty_fifo(_)) -> false.

empty({fifo, [], []}) -> true;

empty({fifo, A, B}) when is_list(A), is_list(B) -> false.

Dialyzer tells that it will ignore the specification because of overlapping domain.

Can somebody tells me where I make a mistake?

I have another point, before trying to define typed fifo I had a version that worked nicely, An Dialyzer show me that nothing prevent the usage of improper lists. Surprizingly, I do not find a simple way (that I can use in a guard) to test for proper/improper character of a list.

It is really strange, because when I use the bif length/1, it is able to fail with the reason badarg!

23> L=[1,2|3]. ==> [1,2|3]

24> is_list(L). ==> true

25> length(L). ==> exception error: bad argument

 in function  length/1

    called as length([1,2|3])

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:03:44+00:00Added an answer on June 10, 2026 at 5:03 pm

    Nothing is wrong with your types and spec. The problem is that the datatype which is used in Dialyzer for the representation of types does not keep as much precision as you are providing. Specifically, the union: {fifo, nonempty_list(A), list(A)} | {fifo, [], nonempty_list(A)} is “crushed” into {fifo, list(A), list(A)}, as the tuples have the same arity (3) and first atom element (fifo). Dialyzer generally does over-approximations (as you can also see here) to make the type analysis more efficient. You can safely ignore this warning.

    For your second question, is_list/1 only checks whether the first constructor of the term that is passed as its argument is a cons cell. Even is_list([1|2]) returns true.

    If you want to ensure that an argument is a proper list you can use a custom function in a case expression like this:

    case is_proper_list(L) of
      true -> ...;
      false -> ...
    end
    
    is_proper_list([]) -> true;
    is_proper_list([_|L]) -> is_proper_list(L);
    is_proper_list(_) -> false.
    

    This can’t be placed in a guard however. In guards you can use the one that you suggest in your comment below (length(L) >= 0).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it's been some time now, since I started reading about android. I've already made
Reading the Jon Skeet book, I have found (some time now) the use of
thank you for taking the time and interest reading this and hopefully helping me
The Kindle has lit a personal interest in reading my various content on it,
Reading the Scala by Example book and there is this example when Martin explains
Reading some questions here on SO about conversion operators and constructors got me thinking
I am fairly new to R and presently reading a book Generalized Additive Models,
I'm writing a book. I have a large notes file, with hyperlinks of interest.
I recently developed an interest in C programming so I got myself a book
Reading this article I thougth automatic property work on .NET Framework 3.0, but some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.