<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">And what about adding sane defaults to the fields, then?<br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><span id="docs-internal-guid-e691a4cc-056a-0210-b8b7-ea8d87d888ad" class=""><span style="font-size: 11pt; font-family: Arial; font-weight: 700; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="Apple-interchange-newline"><hr class=""></span></span><div class=""><b class=""><i class=""><a href="http://about.me/elbrujohalcon" class="">Brujo Benavides</a></i></b></div></div></div><div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><b class=""><br class=""></b></div><br class="Apple-interchange-newline">
</div>
<div style=""><br class=""><blockquote type="cite" class=""><div class="">On 12 Nov 2018, at 08:35, Roger Lipscombe <<a href="mailto:roger@differentpla.net" class="">roger@differentpla.net</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 12 November 2018 at 11:11, Brujo Benavides <<a href="mailto:elbrujohalcon@gmail.com" class="">elbrujohalcon@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">Hi Roger,<br class=""><br class="">According to how you use your record, its spec should actually be…<br class=""><br class="">-record widget {<br class=""> id :: undefined | binary(),<br class=""> name :: undefined | binary(),<br class=""> size :: undefined | integer()<br class="">}.<br class=""><br class="">That will silence dialyzer or, putting it in the right perspective: That<br class="">will be a spec that matches how your code actually treats that record.<br class="">And that’s because: What happens if Props doesn’t have a tuple for name?<br class=""></blockquote><br class="">I figured someone would say that. The answer is that Props *always*<br class="">has a tuple for name -- it was written to a data store with that<br class="">invariant. But I can see that it's hard to tell dialyzer this.<br class=""><br class=""><blockquote type="cite" class="">If not having a {name, Name} tuple in Props is an invalid scenario, you<br class="">should raise some sort of error.<br class="">In that case I would recommend you to keep the record definition as-is, but<br class="">fill the whole record at once:<br class=""><br class="">parse_widget(Props) -><br class=""> #widget{<br class=""> id = get_value(id, Props),<br class=""> name = get_value(name, Props),<br class=""> …<br class=""> }.<br class=""><br class="">get_value(Key, Props) -><br class=""> {Key, Value} = lists:keyfind(Key, 1, Props),<br class=""> Value.<br class=""></blockquote><br class="">I was kinda hoping to avoid that -- I've got a vague feeling that we<br class="">did this for performance reasons. Of course, those assumptions are<br class="">probably no longer valid and need re-checking.<br class=""><br class=""><blockquote type="cite" class="">Hope this helps :)<br class=""></blockquote><br class="">Only in the "you're doing it wrong" sense :)<br class=""></div></div></blockquote></div><br class=""></body></html>