• R/O
  • HTTP
  • SSH
  • HTTPS

transunit: Commit

Transunit repository


Commit MetaInfo

Revisioneef990a7f5780f3ed17e0df636c41d58acf91bc1 (tree)
Zeit2019-05-13 10:34:49
AutorAlaskanEmily <yoloshart@gmai...>
CommiterAlaskanEmily

Log Message

Make maybe comparisons have expressive results

Ändern Zusammenfassung

Diff

--- a/transunit.compare.m
+++ b/transunit.compare.m
@@ -59,10 +59,6 @@
5959
6060 %------------------------------------------------------------------------------%
6161
62-:- func simple_compare(T, T) = maybe.maybe_error.
63-
64-%------------------------------------------------------------------------------%
65-
6662 :- func negate(float) = float.
6763
6864 %------------------------------------------------------------------------------%
@@ -136,7 +132,8 @@
136132 ].
137133
138134 :- instance to_string(maybe.maybe(T)) <= to_string(T) where [
139- (to_string(maybe.yes(That)) = to_string(That)),
135+ (to_string(maybe.yes(That)) =
136+ string.append("maybe.yes(", string.append(to_string(That), ")"))),
140137 (to_string(maybe.no) = "maybe.no")
141138 ].
142139
@@ -154,11 +151,6 @@ generic_compare(A, B) = Result :-
154151
155152 %------------------------------------------------------------------------------%
156153
157-simple_compare(A, B) = Result :-
158- ( A = B -> Result = maybe.ok ; Result = maybe.error("Not equal") ).
159-
160-%------------------------------------------------------------------------------%
161-
162154 :- pred accumulate_mismatch(T, T, list(string), list(string), int, int)
163155 <= compare(T).
164156 :- mode accumulate_mismatch(in, in, in, out, in, out) is det.
@@ -245,7 +237,12 @@ accumulate_mismatch(A, B, !List, I, int.plus(I, 1)) :-
245237 ].
246238
247239 :- instance compare(maybe.maybe(T)) <= (to_string(T), compare(T)) where [
248- func(compare/2) is generic_compare
240+ ( compare(maybe.no, maybe.no) = maybe.ok ),
241+ ( compare(maybe.no, maybe.yes(B)) = maybe.error(
242+ string.append("maybe.no != maybe.yes(", string.append(to_string(B), ")")) )),
243+ ( compare(maybe.yes(A), maybe.no) = maybe.error(
244+ string.append("maybe.yes(", string.append(to_string(A), ") != maybe.no")) )),
245+ ( compare(maybe.yes(A), maybe.yes(B)) = compare(A, B) )
249246 ].
250247
251248 :- instance compare(array.array(T)) <= (to_string(T), compare(T)) where [
Show on old repository browser