<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 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 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>