[m-users.] is there a easy way to wrap Erlang's improper_list/2 and something similar?

Julien Fischer jfischer at opturion.com
Tue Dec 31 14:13:12 AEDT 2013


Hi,

On Thu, 26 Dec 2013, Xiaofeng Yang wrote:

> I'm new to Mercury and trying to use it as a language on Erlang VM
> with strict and obligatory static checker. I've tried to wrap the
> basic list types in Erlang but failed. The following is what I've
> done. I know the definitions are wrong. But I don't know how to wrap
> the improper lists in an easy, expressive, efficient way so that I can
> use them like how I use them in Erlang. Please help me or point me how
> to solve this problem. Thanks.
> 
> In Mercury:
> 
> %% nonempty_improper_list()
> :- type erlang_nonempty_improper_list(Contents, Termination) --->
>           [Contents | Termination]
>         ; [Contents | erlang_nonempty_improper_list(Contents, Termination)].

That won't work; this type defines the constructor '[|]'/2 multiple
times and Mercury doesn't allow that.

> %% wrap improper_list()
> :- type erlang_improper_list(Contents, Termination) --->
>           erlang_improper_list( Termination )           % can't use Termination directly
>         ; erlang_improper_list( erlang_nonempty_improper_list(Contents, Termination) ).

You won't be able to use list terms to construct such a type; however

    :- type improper_list(C, T)
  	--->	nil(T)
 	;	cons(C, improper_list(C, T)).

would be fine.

Cheers,
Julien.


More information about the users mailing list