%------------------------------------------------------------------------------% :- module polymorphism_try_bug. :- interface. :- import_module io. :- type bexpr(V) ---> bexpr(V). :- pred test(bexpr(Var)::in, io::di, io::uo) is det. :- pred test2(bexpr(Var)::in, io::di, io::uo) is det. :- implementation. :- import_module maybe. :- import_module require. :- type bdd(V) ---> bdd(V). test(BooleanExpression, !IO) :- promise_equivalent_solutions [MaybeBDD] ( ( try [] BDDPrime = make_bdd(BooleanExpression) then MaybeBDD = ok(BDDPrime) catch_any ExpPrime -> MaybeBDD = error({"My error message", ExpPrime}) )), ( MaybeBDD = ok(BDD) ; MaybeBDD = error({ErrMessage, _}), write_string(ErrMessage, !IO), sorry($pred, "Error") % throw(Exp) % This also causes the bug. ), io.write(BDD, !IO). % This version of the same code uses a type rather than a tuple, it has the % same problem. :- type my_pair(A, B) ---> my_pair(A, B). test2(BooleanExpression, !IO) :- promise_equivalent_solutions [MaybeBDD] ( ( try [] BDDPrime = make_bdd(BooleanExpression) then MaybeBDD = ok(BDDPrime) catch_any ExpPrime -> MaybeBDD = error(my_pair("My error message", ExpPrime)) )), ( MaybeBDD = ok(BDD) ; MaybeBDD = error(my_pair(ErrMessage, _)), write_string(ErrMessage, !IO), sorry($pred, "Error") % throw(Exp) % This also causes the bug. ), io.write(BDD, !IO). :- func make_bdd(bexpr(V)) = bdd(V). make_bdd(bexpr(V)) = bdd(V).