<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Op 10-8-2015 om 16:23 schreef Jesper
Louis Andersen:<br>
</div>
<blockquote
cite="mid:CAGrdgiUM=E0D4NhoBxzXE3NOJp++NGgGavB83U4F4VfYfSkHJg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Aug 10, 2015 at 2:00 PM,
Roelof Wobben <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">-spec(area()
-> 'ok' | 'error').</blockquote>
</div>
<br>
</div>
<div class="gmail_extra">(Sean is beating me to it by a few
minutes, but I have some things in here that pushes different
perspectives on his answer, so I'll post it anyway)<br>
</div>
<div class="gmail_extra"><br>
</div>
<div class="gmail_extra">This is not the precise way to specify
a function. I think it may work since the parens around the
specification are ignored, but I wouldn't rely on it. See<br>
<br>
<a moz-do-not-send="true"
href="http://erlang.org/doc/reference_manual/typespec.html">http://erlang.org/doc/reference_manual/typespec.html</a><br>
<br>
</div>
<div class="gmail_extra">and the section "Function
specifications". The notation for the above would be<br>
<br>
</div>
<div class="gmail_extra">-spec area() -> 'ok' | 'error'.<br>
<br>
</div>
<div class="gmail_extra">Anyway, on to the error. The problem is
we have a spec for prompt_user/1 that looks like the
following:<br>
<br>
-spec prompt_user(string()) -> string().<br>
<br>
But then you define:<br>
<br>
number_from_user(Name) -><br>
Prompt = ["Enter ", Name, " > "],<br>
to_positive_number(prompt_user(Prompt)).<br>
<br>
</div>
<div class="gmail_extra">Note how the type we call with is a
list(string()). This clearly breaks the contract in the code,
since you said this can't occur in the -spec. At this point,
it is often clever to ask the `typer` tool what it believes
the type is, or you can change the code: either by altering
the Prompt value in number_from_user/1 (lists:append/1 might
come in handy here), or by switching the spec:<br>
<br>
</div>
<div class="gmail_extra">-spec prompt_user(Input) -> string()<br>
</div>
<div class="gmail_extra"> when Input :: string() |
[string()].<br>
<br>
</div>
<div class="gmail_extra">However, you may need to be more
precise given that Unicode is in the game here. <br>
</div>
<div class="gmail_extra"><br clear="all">
<br>
-- <br>
<div class="gmail_signature">J.</div>
</div>
</div>
</blockquote>
<br>
<br>
Thanks for the tip.<br>
With Typer you mean the TypeEr tool explained here ?<br>
<br>
Roelof<br>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="https://www.avast.com/antivirus">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" alt="Avast logo" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
<br><a href="https://www.avast.com/antivirus">www.avast.com</a>
</p>
</td>
</tr>
</table>
<br />
</body>
</html>