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

Ulf Wiger ulf.wiger@REDACTED
Wed Jan 13 19:11:29 CET 2010


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



More information about the erlang-questions mailing list