<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Stavros,</div><div><br></div><div>Ok sorry for not stating my aims so clearly. I am looking at various ways to formalise my API declarations and make dynamic binding to implementations cleaner than having code that does `Mod = orddict, ...'. So for example, to go back to the recent discussions about having a unified API for dict. Instead of </div><div><br></div><div>Mod = orddict,</div><div>%% some more code...</div><div>Mod:fetch(.....)</div><div><br></div><div>I would like to be able to bind to an implementation once, and then after that use the generic module/api in my code:</div><div><br></div><div>true = dictionary:is_key(a, dict:from_list([{a, 1}])),</div><div>true = dictionary:is_key(a, orddict:from_list([{a, 1}])),</div><div>true = dictionary:is_key(a, gb_trees:from_orddict(orddict:from_list([{a, 1}]))).</div><div><br></div><div><br></div><div>So I was thinking about various ways to bind these, both at compile time and at runtime based on the conversation about Clojure's 'prototypes'. My general thought is that an implementation of the 'prototype' behaviour defined by the 'dictionary' module will basically be resolved based on the type(s) of the 1..* arguments the various behaviour callback functions are bound over. So if you've defined is_key like so:</div><div><br></div><div>-spec is_key(term(), dictionary:instance(dictionary:unbound_type_parameter())) -> boolean(). </div><div><br></div><div>then you will create many instances, one for dict, one for orddict, one for gb_trees, etc. Where the module 'natively' implements the interface, there's little work to do other than 'stating' (or registering somehow) that you consider it an implementation/instance of the prototype - forgive me I don't have a better term for this. For gb_trees, you'd basically write an implementation for each of the prototype's functions that need 'rewiring', such that you'd get</div><div><br></div><div>-module(gb_trees_dictionary).</div><div>-implements(dictionary, gb_trees:gb_tree()).</div><div><br></div><div>-spec is_key(term(), dictionary:instance(gb_trees:gb_tree())) -> boolean().</div><div>is_key(K, D) -> </div><div>    gb_trees:is_defined(K, D).</div><div><br></div><div><div><br></div><div>At compile time (or at runtime, possibly though beam code rewriting), I want to use the type specs for the various -implements modules (which could equally be declared anonymously using funs) to resolve the callee. Currently, there's very little to help me work with type specs. I can pull them out of the abstract code, but they're pretty 'low level' structures and AFAIK aren't documented anywhere. Now I'm simply assuming that there is loads of useful code in PropEr and Dialyzer that 'understands' these spec related data structures and was hoping I could make use of it, rather than learn my way around by fumbling in the dark. </div><div><br></div><div>Hope that makes sense of how I'm trying to save myself a bit of time.</div><div><br></div><div>Cheers,</div><div><br></div><div>Tim</div><div><br></div><div>On 1 Mar 2012, at 21:03, Stavros Aronis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Tim!<div><br></div><div>I am not sure what you mean by a "type server", as Dialyzer does not really have a "component" that I could imagine being separated and labeled so. Dialyzer has the ability to store the specs and exported types in the PLT and from there use them to increase the precision of the analysis it performs.</div><div><br></div><div>What do you mean by "working with types"?</div><div><br></div><div>Regards,</div><div>Stavros<br><br>On Thursday, March 1, 2012 4:43:33 PM UTC+1, Tim Watson wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Hi all,<p>Both PropEr and Dialyzer appear to have a 'type server' that provides functions for working with type specs. What are the chances of this being available as a separate unit? There is currently very little support for working with types, as the previous post about lack of support in erl_syntax pointed out. It would be nice to see type specs being better supported.</p><p>Cheers,</p><p>Tim<br>______________________________<wbr>_________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br></p><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div></blockquote></div>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><br></body></html>