[erlang-questions] lists:concat with non-string sublists

James Aimonetti james@REDACTED
Wed May 23 19:20:51 CEST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/23/2012 01:37 AM, Ladislav Lenart wrote:
> Hello.
> 
> On 22.5.2012 20:46, James Aimonetti wrote:
>>>> [snip] So, according to the docs, I would expect:
>>>> 
>>>>> lists:concat([[{foo, 123}], [{bar, 234}]]).
>>>> 
>>>> to fail. It doesn't, and returns [{foo, 123}, {bar,234}].
>>>> Reading the implementation of concat/1 its easy to see why
>>>> this works.
>>>> 
>>> [snip]
>>> 
>>> Typical example of this is something like lists:append/2:
>>> 
>>> -spec append(list(), list()) -> list(). % or something more 
>>> involved
>>> 
>>> but the implementation may allow for calls of the form:
>>> 
>>> Eshell V5.9.2  (abort with ^G) 1> lists:append([], 3.14). 3.14
>>> 
>>> but you probably would not want to change its spec to allow
>>> term() for its second argument and return, would you?
>> 
>> Indeed not, wrt to the lists:append/2 example. I guess the safer 
>> course of action, in my case, is to implement my own concat/1 for
>> my list of lists of tuples, to ensure that lists:concat/1 doesn't
>> change down the road to enforce the spec more strictly?
> 
> What about lists:append/1? That should be suitable for your use
> case, or am I missing something?
> 
> 
> Ladislav Lenart
> 
> 
> 

lists:append/1 is certainly more suitable. I was running Dialyzer on
code I hadn't written and was surprised that lists:concat/1 didn't
enforce the spec more tightly and error on the input I gave it.


- -- 
James Aimonetti
Distributed Systems Engineer / DJ MC_

2600hz | http://2600hz.com
sip:james@REDACTED
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPvRxzAAoJENc77s1OYoGgu7sH/3gIT1/7ES8tXR8sb+lnhKfC
rBhWyUHV2AnJlYpxZpI/IYMtFurvM9tb1lbVdmU4Ufyz2i0T3MttRWjkcnJoaqIe
IYdbD3FJqpbkVgMzxCb/MLVerzkdR/9aMZtUNL9EKJrEebPb/pMg7HQ/EMScN0Ff
1UlyPK/D8eM45f3S8Ia6L9ZMHMSdDRLy5PcV7NB//He+b+uqxEfNM0u0BLcVP6IX
HUGb87AhPOkAz9Vbe7fNME3FWdOGWeecx/Xae0LjgKfdVDutVVvUpo6BZDJLBuFS
4O7+RqKP6GSnf8e9UNtOBGNV03HpVCJgk3a4ZAQhl/OH1sa1eO5Z6Ent8sfAzyw=
=pVeM
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list