[erlang-questions] type specs to guards, anyone?

Ulf Wiger <>
Wed Jan 13 19:14:27 CET 2010


Sorry, I jotted that down from memory, and didn't
quite get it right.

It should have been t_is_instance/2, t_from_term/1
and t_from_form/1.

Br,
Ulf W

Ulf Wiger wrote:
> 
> The easy generic solution seems to be
> 
> erl_types:f_is_instance(erl_types:f_from_term(Value), T),
> 
> where T = erl_types:f_from_form(Form) at compile-time.
> 
> My objective is to generate type-checking code from
> type signatures. It doesn't have to be guards, obviously.
> I'm quite content with a solution that handles all type
> specifications, with the option to selectively generate
> faster code for some commonly used types.
> 
> BR,
> Ulf W
> 
> Kostis Sagonas wrote:
>> Ulf Wiger wrote:
>>>
>>> Does anyone happen to be sitting on code that generates guard
>>> tests from type specs?
>>
>> I am not aware of such code.
>>
>> Moreover, I am not even sure what you want to do here.  The language 
>> of types allows for more things than what you can express using Erlang 
>> guards.  For example, you might have a function foo/1 whose argument 
>> should be a list of integers.
>>
>> -spec foo([integer()]) ->
>>
>> Using guards the only thing you can express is that foo/1 takes a 
>> proper list.  You need to be able to employ user-defined functions in 
>> guards to do it properly. Erlang currently lacks this.
>>
>> Kostis
> 
> ---------------------------------------------------
> 
> ---------------------------------------------------
> 
> WE'VE CHANGED NAMES!
> 
> Since January 1st 2010 Erlang Training and Consulting Ltd. has become 
> ERLANG SOLUTIONS LTD.
> 
> www.erlang-solutions.com
> 
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
> 
> ---------------------------------------------------
> 
> ---------------------------------------------------
> 
> WE'VE CHANGED NAMES!
> 
> Since January 1st 2010 Erlang Training and Consulting Ltd. has become 
> ERLANG SOLUTIONS LTD.
> 
> www.erlang-solutions.com
> 

---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list