From 2b60a46d673361dfa72f27b1d8b14cf5695c92b4 Mon Sep 17 00:00:00 2001 From: AlaskanEmily Date: Sun, 7 Jul 2019 10:50:26 -0700 Subject: [PATCH] Add compare instance for maybe.maybe_error --- transunit.compare.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/transunit.compare.m b/transunit.compare.m index 7e26042..784afc8 100644 --- a/transunit.compare.m +++ b/transunit.compare.m @@ -55,6 +55,8 @@ :- instance compare(maybe.maybe(T)) <= (to_string(T), compare(T)). :- instance compare(array.array(T)) <= (to_string(T), compare(T)). :- instance compare(array2d.array2d(T)) <= (to_string(T), compare(T)). +:- instance compare(maybe.maybe_error(T, E)) + <= (to_string(T), compare(T), to_string(E), compare(E)). %------------------------------------------------------------------------------% @@ -297,6 +299,21 @@ accumulate_mismatch(A, B, !List, I, int.plus(I, 1)) :- ) ]. +:- instance transunit.compare(maybe.maybe_error(T, E)) + <= (transunit.to_string(T), transunit.compare(T), + transunit.to_string(E), transunit.compare(E)) where [ + ( compare(maybe.ok(A), maybe.ok(B)) = transunit.compare(A, B) ), + ( compare(maybe.error(A), maybe.error(B)) = transunit.compare(A, B) ), + ( compare(maybe.ok(OK), maybe.error(E)) = + maybe.error(string.append( + string.append("OK:", transunit.to_string(OK)), + string.append(" != Error:", transunit.to_string(E)))) ), + ( compare(maybe.error(E), maybe.ok(OK)) = + maybe.error(string.append( + string.append("Error:", transunit.to_string(E)), + string.append(" != OK:", transunit.to_string(OK)))) ) +]. + %------------------------------------------------------------------------------% negate(X) = -X. -- 2.11.0