Skip to content

Commit 380ae2f

Browse files
committed
Fix to not to use polymorphic equality in examples
Especially in the case of Set and Map abstractions that are supposed to use given ordering.
1 parent 4a2e105 commit 380ae2f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

prelude.1ml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ true = Bool.true;
2929
false = Bool.false;
3030
not = Bool.not;
3131

32-
(==) 'a (x : a) (y : a) = primitive "==" a (x, y);
33-
(<>) 'a (x : a) (y : a) = not (x == y);
32+
PolyEq (type t) = {
33+
(==) (x : t) (y : t) = primitive "==" t (x, y);
34+
(<>) (x : t) (y : t) = not (x == y);
35+
};
3436

37+
Bool = {
38+
include Bool;
39+
include PolyEq t;
40+
};
3541

3642
;; Int
3743

@@ -49,6 +55,7 @@ Int =
4955
(<=) l r = primitive "Int.<=" (l, r);
5056
(>=) l r = primitive "Int.>=" (l, r);
5157
print = primitive "Int.print";
58+
include PolyEq t;
5259
};
5360
type int = Int.t;
5461
(+) = Int.+;
@@ -60,6 +67,7 @@ type int = Int.t;
6067
(>) = Int.>;
6168
(<=) = Int.<=;
6269
(>=) = Int.>=;
70+
(==) = Int.==;
6371

6472

6573
;; Char
@@ -71,6 +79,7 @@ Char =
7179
toInt = primitive "Char.toInt";
7280
fromInt = primitive "Char.fromInt";
7381
print = primitive "Char.print";
82+
include PolyEq t;
7483
};
7584
type char = Char.t;
7685

@@ -90,6 +99,7 @@ Text =
9099
sub t i = primitive "Text.sub" (t, i);
91100
fromChar c = primitive "Text.fromChar" c;
92101
print = primitive "Text.print";
102+
include PolyEq t;
93103
};
94104
type text = Text.t;
95105
(++) = Text.++;
@@ -186,7 +196,7 @@ List :> LIST =
186196
filter xs f = foldr xs nil (fun x ys => if f x then cons x ys else ys);
187197
nth xs n =
188198
(foldr xs (length xs - 1, none) (fun x (p : (_, _)) =>
189-
(p.1 - 1, if p.1 == n then some x else p.2)
199+
(p.1 - 1, if Int.== p.1 n then some x else p.2)
190200
) ).2;
191201
};
192202

@@ -215,6 +225,7 @@ type SET =
215225
Set (Elem : ORD) :> SET with (elem = Elem.t) =
216226
{
217227
type elem = Elem.t;
228+
(==) x y = let include Elem in (x <= y) and (y <= x);
218229
type set = (int, elem -> bool);
219230
type t = set;
220231
empty = (0, fun (x : elem) => false);
@@ -241,6 +252,7 @@ type MAP =
241252
Map (Key : ORD) :> MAP with (key = Key.t) =
242253
{
243254
type key = Key.t;
255+
(==) x y = let include Key in (x <= y) and (y <= x);
244256
type map a = key -> opt a;
245257
t = map;
246258
empty x = none;

0 commit comments

Comments
 (0)