[mercury-users] inst of list in non-empty branch
Ian MacLarty
maclarty at csse.unimelb.edu.au
Fri Mar 30 12:47:11 AEST 2007
On Fri, Mar 30, 2007 at 12:02:08PM +1000, Julien Fischer wrote:
>
> On Thu, 29 Mar 2007 doug.auclair at logicaltypes.com wrote:
>
> >This leads me to suspect that the mode for Kids is set to only 'in', even
> >in this non-empty-list clause. ... I have seen the mode system set the
> >inst properly for other user-defined discriminated union types,
> >particularly
> >when implementing different modes for different clauses (as illustrated in
> >the refman, sect 4.4) so it's puzzling why this particular example is being
> >uncooperative.
> >
> >Is there a pragma or assertion where I can assign the inst to Kids? Is
> >there some call-out-to-C hackery that would force the inst assignment?
>
> We usually resort to something like:
>
> :- pred unsafe_cast_to_foo(type::in, type::out(foo)) is det.
>
> :- pragma foreign_proc("C",
> unsafe_cast_to_foo(A::in, B::out(foo)),
> [will_not_call_mercury, promise_pure, thread_safe],
> "
> B = A;
> ").
>
The following would be safer:
:- pred det_cast_to_foo(t::in, t::out(foo)) is det.
det_cast_to_foo(T, F) :-
( T = foo ->
F = foo
;
error("T not a foo")
).
or
:- pred det_cast_to_foo(t).
:- mode det_cast_to_foo(ground >> foo).
det_cast_to_foo(T) :-
( T = foo
; T = bar,
error("bar")
).
although in your case the solution I posted earlier should work I think.
Ian.
--------------------------------------------------------------------------
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