[erlang-questions] [Dialyser] Type parametrized behaviours

Matthew Sackman <>
Wed Apr 25 12:14:16 CEST 2012


On Tue, Apr 24, 2012 at 02:17:06PM -0700, Stavros Aronis wrote:
> Ok, I understand your original approach now. It is indeed clever and 
> reduces duplication.

Just for purposes of another example, one which shows several
narrowings, the same technique is used heavily in erlando.

Behaviour:
https://github.com/rabbitmq/erlando/blob/master/src/monad.erl

Specs:
https://github.com/rabbitmq/erlando/blob/master/include/monad_specs.hrl

Refinement:
https://github.com/rabbitmq/erlando/blob/master/src/identity_m.erl
https://github.com/rabbitmq/erlando/blob/master/src/error_m.erl
https://github.com/rabbitmq/erlando/blob/master/src/maybe_m.erl
https://github.com/rabbitmq/erlando/blob/master/src/list_m.erl
https://github.com/rabbitmq/erlando/blob/master/src/state_t.erl
https://github.com/rabbitmq/erlando/blob/master/src/error_t.erl

Note that some of those refinements (eg maybe_m) also bring in the specs
from
https://github.com/rabbitmq/erlando/blob/master/include/monad_plus_specs.hrl
and that both sets of specs make use of the *same* type parameter name.

The point is that it allows you to define the specs with named
polymorphism and then to narrow those types as the specialisations
require. In the case of erlando, the narrowing still leads to
polymorphic types, though normally narrower, whereas the rmq example
reduced the types to fully ground types.

Just 



More information about the erlang-questions mailing list