dialyzer: user-defined types just synonyms?
Dmitry Belyaev
rumata-estor@REDACTED
Thu Apr 22 13:42:24 CEST 2010
I want to define my type as a synonym for built-in type. But I want
dialyzer to warn me if a function is called with wrong type.
I have following code and dialyzer says everything is nice. But I want
it to warn about "StrFromStr = my_to_str(Str)" line.
Can I make it? How?
I remember Haskell's "newtype" would be of desired behaviour.
-module(test).
-export([start/1]).
-type my_str() :: string().
-spec start(string()) -> tuple().
start(Str0) ->
MyStr = str_to_my(Str0),
Str = my_to_str(MyStr),
MyFromMy = str_to_my(MyStr),
StrFromStr = my_to_str(Str),
{Str, MyFromMy, StrFromStr}.
-spec str_to_my(string()) -> my_str().
str_to_my(Str) ->
Str.
-spec my_to_str(MyStr) -> string() when is_subtype(MyStr, my_str()).
my_to_str(MyStr) ->
MyStr.
More information about the erlang-questions
mailing list