<br><font size=2 face="sans-serif">Hi,</font>
<br>
<br><font size=2 face="sans-serif">Thanks Kostis for your answer. I was
just thinking that if the developer could provide enough information, the
compiler and/or runtime could determine that the returned result (here
an atom) is not used, and thus maybe optimise it out. One step further
is allowing the function developer not even to bother ending each clause
of this function with such an atom, as anyway this result would be ignored.</font>
<br>
<br><font size=2 face="sans-serif">Admittedly it is premature optimisation,
but on the other hand having to return *explicitly* a value that is known
never to be used is a bit weird!<br>
</font>
<br><font size=2 face="sans-serif">I think I will try to stick to '-opaque
void() :: any().', trusting user code not to mess with return values (and
catching any attempt of doing so thanks to Dialyzer), and will fall back
to something like: '</font><tt><font size=2>-opaque 'void() :: 'VoiD'.'
(and thus adding the returning of this atom everywhere needed) if the first
approach had drawbacks I did not anticipate.</font></tt>
<br>
<br><font size=2 face="sans-serif">Thanks again!</font>
<br><font size=2 face="sans-serif">Best regards,</font>
<br><font size=2 face="sans-serif"><br>
Olivier.<br>
---------------------------<br>
Olivier Boudeville<br>
<br>
EDF R&D : 1, avenue du Général de Gaulle, 92140 Clamart, France<br>
Département SINETICS, groupe ASICS (I2A), bureau B-226<br>
Office : +33 1 47 65 59 58 / Mobile : +33 6 16 83 37 22 / Fax : +33 1 47
65 27 13</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>kostis@cs.ntua.gr</b> </font>
<br><font size=1 face="sans-serif">Envoyé par : erlang-questions-bounces@erlang.org</font>
<p><font size=1 face="sans-serif">18/11/2011 20:12</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">A</font></div>
<td><font size=1 face="sans-serif">erlang-questions@erlang.org</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Objet</font></div>
<td><font size=1 face="sans-serif">Re: [erlang-questions] void() in type
specs</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2>On 11/18/11 15:25, Olivier BOUDEVILLE wrote:<br>
><br>
> Hi,<br>
><br>
> How can we define a type spec for a function which is useful only
for<br>
> its side effects (not returning anything of interest to the caller)?<br>
><br>
> In the documentation of various modules there are functions that are<br>
> said to return 'void()' (ex: erlang:purge_module/1), however the<br>
> compiler complains if I want to use it in my code ("type void()<br>
> undefined") and void() is not mentioned in<br>
> http://www.erlang.org/doc/reference_manual/typespec.html<br>
><br>
> I imagine we could define such a "don't care"-type with
a '-opaque<br>
> void() :: any().' but wouldn't it be more practical if it was a built-in<br>
> keyword? Moreover it could allow Dialyzer to check that the result
is<br>
> indeed never used (or maybe I overlooked something?)<br>
<br>
There is no void() in Erlang and functions that return always return <br>
some value. To my mind, the only sensible values for don't care returns
<br>
are atoms. The atoms 'ok' or 'void' are among the best such values you
<br>
can get. Whether callers are supposed to check or depend on this value
<br>
or not is a different matter. If you don't care, simply write these <br>
functions as follows:<br>
<br>
foo(...) -><br>
    ... DO LOTS OF SIDE-EFFECTS HERE ...,<br>
    ... MORE SIDE EFFECTS ...,<br>
    ok.<br>
<br>
and spec them as:<br>
<br>
-spec foo(...SOME TYPES...) -> 'ok'.<br>
<br>
or if you prefer,<br>
<br>
-type void() :: 'ok'.<br>
-spec foo(...SOME TYPES...) -> void().<br>
<br>
<br>
If you absolutely want to guarantee that there is no pattern matching <br>
with this void(), choose some weird atom for their return (eg. 'VoiD')
<br>
and then declare this return value opaque:<br>
<br>
-opaque void() :: 'VoiD'.<br>
<br>
Dialyzer will then warn you for all cases that you trying to explicitly
<br>
pattern match with this return.<br>
<br>
But, out of curiosity, why guaranteeing that there is no matching with
<br>
whatever happens to be used for void() is so important to you?<br>
<br>
<br>
Kostis<br>
_______________________________________________<br>
erlang-questions mailing list<br>
erlang-questions@erlang.org<br>
http://erlang.org/mailman/listinfo/erlang-questions<br>
</font></tt>
<br><font face="monospace"><br>
<br>
<br>
Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à l'intention exclusive des destinataires et les informations qui y figurent sont strictement confidentielles. Toute utilisation de ce Message non conforme à sa destination, toute diffusion ou toute publication totale ou partielle, est interdite sauf autorisation expresse.<br>
<br>
Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de votre système, ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support que ce soit. Nous vous remercions également d'en avertir immédiatement l'expéditeur par retour du message.<br>
<br>
Il est impossible de garantir que les communications par messagerie électronique arrivent en temps utile, sont sécurisées ou dénuées de toute erreur ou virus.<br>
____________________________________________________<br>
<br>
This message and any attachments (the 'Message') are intended solely for the addressees. The information contained in this Message is confidential. Any use of information contained in this Message not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval.<br>
<br>
If you are not the addressee, you may not copy, forward, disclose or use any part of it. If you have received this message in error, please delete it and all copies from your system and notify the sender immediately by return message.<br>
<br>
E-mail communication cannot be guaranteed to be timely secure, error or virus-free.</font>