Skip to content

Commit

Permalink
Fix to not to use polymorphic equality in examples
Browse files Browse the repository at this point in the history
Especially in the case of Set and Map abstractions that are supposed to use
given ordering.
  • Loading branch information
polytypic committed Jan 21, 2020
1 parent bf4fbe6 commit 77ab9bb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions prelude.1ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ true = Bool.true;
false = Bool.false;
not = Bool.not;

(==) 'a (x : a) (y : a) = primitive "==" a (x, y);
(<>) 'a (x : a) (y : a) = not (x == y);
PolyEq (type t) = {
(==) (x : t) (y : t) = primitive "==" t (x, y);
(<>) (x : t) (y : t) = not (x == y);
};

Bool = {
include Bool;
include PolyEq t;
};

;; Int

Expand All @@ -49,6 +55,7 @@ Int =
(<=) l r = primitive "Int.<=" (l, r);
(>=) l r = primitive "Int.>=" (l, r);
print = primitive "Int.print";
include PolyEq t;
};
type int = Int.t;
(+) = Int.+;
Expand All @@ -60,6 +67,7 @@ type int = Int.t;
(>) = Int.>;
(<=) = Int.<=;
(>=) = Int.>=;
(==) = Int.==;


;; Char
Expand All @@ -71,6 +79,7 @@ Char =
toInt = primitive "Char.toInt";
fromInt = primitive "Char.fromInt";
print = primitive "Char.print";
include PolyEq t;
};
type char = Char.t;

Expand All @@ -90,6 +99,7 @@ Text =
sub t i = primitive "Text.sub" (t, i);
fromChar c = primitive "Text.fromChar" c;
print = primitive "Text.print";
include PolyEq t;
};
type text = Text.t;
(++) = Text.++;
Expand Down Expand Up @@ -186,7 +196,7 @@ List :> LIST =
filter xs f = foldr xs nil (fun x ys => if f x then cons x ys else ys);
nth xs n =
(foldr xs (length xs - 1, none) (fun x (p : (_, _)) =>
(p.1 - 1, if p.1 == n then some x else p.2)
(p.1 - 1, if Int.== p.1 n then some x else p.2)
) ).2;
};

Expand Down Expand Up @@ -215,6 +225,7 @@ type SET =
Set (Elem : ORD) :> SET with (elem = Elem.t) =
{
type elem = Elem.t;
(==) x y = let include Elem in (x <= y) and (y <= x);
type set = (int, elem -> bool);
type t = set;
empty = (0, fun (x : elem) => false);
Expand All @@ -241,6 +252,7 @@ type MAP =
Map (Key : ORD) :> MAP with (key = Key.t) =
{
type key = Key.t;
(==) x y = let include Key in (x <= y) and (y <= x);
type map a = key -> opt a;
t = map;
empty x = none;
Expand Down

0 comments on commit 77ab9bb

Please sign in to comment.