[erlang-questions] behavior of lists:append/1

zxq9 zxq9@REDACTED
Mon Sep 23 10:17:25 CEST 2019


On 2019/09/23 17:08, Raimo Niskanen wrote:
> On Thu, Sep 19, 2019 at 06:54:29AM +0900, zxq9 wrote:
>> On 2019/09/18 21:00, Raimo Niskanen wrote:
>>> On Tue, Sep 17, 2019 at 11:25:11PM +0900, zxq9 wrote:
>>>> On 2019/09/17 22:13, Raimo Niskanen wrote:
>>>>> On Mon, Sep 16, 2019 at 10:53:57PM +0900, zxq9 wrote:
>>>>> No.
>>>>>
>>>>> lists:append/2 can be used and *is* used by existing code to construct
>>>>> improper lists.  It would break backwards compatibility.
>>>
>>> ...to construct improper lists even as in appending a tail element (that is
>>> need not be a list) to a list...
>>
>> At least here we can put down a line and say "that's a violation of the
>> typespec", because it is:
>> http://erlang.org/doc/man/lists.html#append-2
> 
> You are right.
> 
> I dug up this discussion:
>      http://erlang.org/pipermail/erlang-questions/2013-March/073022.html
> 
> And from that I draw these conclusions:
> * The type specs and documentation describe the intention of the API
> * If the arguments follow the type spec, so will the return value
> * If not, it will not, but there is no guarantee for e.g an exception
> * Code may be more lenient that its type spec
> 
> So, if you use lists:append/1,2 to construct an improper list you will get
> a Dialyzer warning, even though the code works.
> 
> We will not change the implementation of lists:append/1,2 for effeciency
> and legacy reasons.  If anything should change it should be the type spec
> and documentation, but I see no good reason why.  Now you get a warning
> from Dialyzer for "bad style" according to some definition of it, which
> many think is a good thing.
> 
> Dialyzer only makes guarantees about code that follows the type specs.
> Code that does not follow the type specs might work anyway.
> 
> I suspect this whole thread originates in a misunderstanding about what
> type specs specify and not...

Makes sense.

I tend to follow Dialyzer almost religiously on projects where I need 
hot upgrades, so am probably giving its returns too much weight.

I'll bookmark your response to reference the next time this conversation 
pops up.

Regards
-Craig



More information about the erlang-questions mailing list