[mercury-users] mode/inst etc

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jan 3 09:05:32 AEDT 2008


On Wed, 2 Jan 2008, Tomas By wrote:

> Hello,
>
> Suppose I have a type:
>
>  :- type tree(K,V) ---> empty ; tree(K,V,tree(K,V),tree(K,V)).
>
> and a procedure that is only ever called for a non-empty tree:
>
>  :- pred dosomething(tree(K,V)::in,K::out,V::out) is det.
>
> I could write
>
>  dosomething(tree(K,V,_,_),K,V).
>  dosomething(empty,_,_) :- error("Tree is empty").
>
> but it would be nicer if I could tell the compiler to not allow the tree
> to be empty. Perhaps something like
>
>  :- mode intree == in(tree(bound,bound)).

It should be:

:- mode intree == in(bound(tree(ground, ground, ground, ground))).

Since that is a little verbose, I suggest using a separate inst
definition, e.g.

:- inst non_empty_tree ---> tree(ground, ground, ground, ground).
:- mode intree == in(non_empty_tree).

>  :- pred dosomething(tree(K,V)::intree,K::out,V::out) is det.
>
> Is this possible? What should the code like? (The above does not work)

See above.

Cheers,
Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list