refactor Ord to be based on compare

This commit is contained in:
2024-12-29 16:16:49 -08:00
parent 413f95940f
commit 6397cac18a
11 changed files with 47 additions and 57 deletions

View File

@@ -51,7 +51,7 @@ instance Sub BigInt where a - b = subbi a b
instance Cast Int BigInt where cast x = itobi x
instance Eq BigInt where a == b = jsEq a b
instance Show BigInt where show = jsShow
instance Ord BigInt where a < b = jsLT a b
instance Ord BigInt where compare a b = jsCompare a b
calcCost : BigInt Machine Maybe BigInt
calcCost extra (MkMachine (ax, ay) (bx, by) (px, py)) =

View File

@@ -72,7 +72,7 @@ dirVal East = 2
dirVal West = 3
instance Ord Dir where
a < b = dirVal a < dirVal b
compare a b = compare (dirVal a) (dirVal b)
instance Eq Dir where
a == b = dirVal a == dirVal b

View File

@@ -21,7 +21,7 @@ instance Sub BigInt where a - b = subbi a b
instance Cast Int BigInt where cast x = itobi x
instance Eq BigInt where a == b = jsEq a b
instance Show BigInt where show = jsShow
instance Ord BigInt where a < b = jsLT a b
instance Ord BigInt where compare a b = jsCompare a b
data Machine : U where
M : BigInt BigInt BigInt List Int Int SnocList Int Machine

View File

@@ -23,7 +23,7 @@ instance Sub BigInt where a - b = subbi a b
instance Cast Int BigInt where cast x = itobi x
instance Eq BigInt where a == b = jsEq a b
instance Show BigInt where show = jsShow
instance Ord BigInt where a < b = jsLT a b
instance Ord BigInt where compare a b = jsCompare a b
infixl 7 _%_
pfunc _%_ : BigInt BigInt BigInt := `(x,y) => x % y`

View File

@@ -26,7 +26,7 @@ instance Sub BigInt where a - b = subbi a b
instance Cast Int BigInt where cast x = itobi x
instance Eq BigInt where a == b = jsEq a b
instance Show BigInt where show = jsShow
instance Ord BigInt where a < b = jsLT a b
instance Ord BigInt where compare a b = jsCompare a b
-- base: 30s
-- switching from tuple to int: 8 s

View File

@@ -18,7 +18,7 @@ instance Eq Op where
_ == _ = False
record Gate where
constructor GT
constructor MkG
in1 : String
in2 : String
op : Op
@@ -49,7 +49,7 @@ parseFile text = do
parseGate s = do
let (in1 :: op :: in2 :: _ :: out :: Nil) = split s " " | _ => Left $ "bad gate: " ++ s
op <- getOp op
Right $ GT in1 in2 op out
Right $ MkG in1 in2 op out
State : U
@@ -114,10 +114,10 @@ range : Int → Int → List Int
range a b = if a < b then a :: range (a + 1) b else Nil
swapPins : String String Gate Gate
swapPins a g (GT i1 i2 op out) =
if out == a then GT i1 i2 op g
else if out == g then GT i1 i2 op a
else GT i1 i2 op out
swapPins a g (MkG i1 i2 op out) =
if out == a then MkG i1 i2 op g
else if out == g then MkG i1 i2 op a
else MkG i1 i2 op out
fail : a. String -> a
fail msg = let x = trace "FAIL" msg in ?

View File

@@ -28,7 +28,7 @@ instance Eq Dir where
a == b = show a == show b
instance Ord Dir where
a < b = show a < show b
compare a b = compare (show a) (show b)
Done : U
Done = SortedMap (Point × Dir) Unit