Give alternate default definition for (<=)

I have following datatype for representing arbitrary computable numbers: newtype Computable = Inexact (Word -> Integer) "Inexact" encapsulates Cauchy sequences. min and max will halt: instance Ord Computable where min (Inexact f) (Inexact g) = Inexact (\n -> min (f n) (g n)) max (Inexact f) (Inexact g) = Inexact (\n -> max (f n) (g n)) But comparison functions won't halt for same numbers: compare (Inexact f) (Inexact g) = go 0 where go n = compare (f n) (g n) <> go (n+1) So in this case, it would be inappropriate to defaultly define min and max. It would be nice if there was a function for alternately defining comparison functions: defaultLessThan :: Ord a => a -> a -> Bool defaultLessThan x y = x == y || x == min x y Then we can let (<=) = defaultLessThan. Also I have to mention that the "realAbs" function I suggested in January must be the following definition in this regard: realAbs x = max x (negate x)

"defaultLTorEQ" would be a better name, since it's for (<=), not (<).
2020년 5월 8일 (금) 오전 10:49, Dannyu NDos
I have following datatype for representing arbitrary computable numbers:
newtype Computable = Inexact (Word -> Integer)
"Inexact" encapsulates Cauchy sequences.
min and max will halt:
instance Ord Computable where min (Inexact f) (Inexact g) = Inexact (\n -> min (f n) (g n)) max (Inexact f) (Inexact g) = Inexact (\n -> max (f n) (g n))
But comparison functions won't halt for same numbers:
compare (Inexact f) (Inexact g) = go 0 where go n = compare (f n) (g n) <> go (n+1)
So in this case, it would be inappropriate to defaultly define min and max.
It would be nice if there was a function for alternately defining comparison functions:
defaultLessThan :: Ord a => a -> a -> Bool defaultLessThan x y = x == y || x == min x y
Then we can let (<=) = defaultLessThan.
Also I have to mention that the "realAbs" function I suggested in January must be the following definition in this regard:
realAbs x = max x (negate x)

Am Fr., 8. Mai 2020 um 03:50 Uhr schrieb Dannyu NDos : I have following datatype for representing arbitrary computable numbers: newtype Computable = Inexact (Word -> Integer) "Inexact" encapsulates Cauchy sequences. min and max will halt: instance Ord Computable where [...] Eq is a superclass of Ord, so how do you define that for Computable?
participants (2)
-
Dannyu NDos
-
Sven Panne