[erlang-questions] dialyzer: user-defined types just synonyms?

Dmitry Belyaev rumata-estor@REDACTED
Thu Apr 22 16:19:32 CEST 2010


So is it impossible to distinguish plain string came from user and 
string prepared for database (escaped)?
I don't want to put it in some container like tuple.

Kostis Sagonas wrote:
>
> Dmitry Belyaev wrote:
>> 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?
>
> You cannot make it.  The notion of equality between types is 
> structural, not nominative. 
> (http://en.wikipedia.org/wiki/Structural_type_system)
>
> Kostis
>
>> 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.
>>
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>



More information about the erlang-questions mailing list