import Data.Function (on)
import Data.List (sort)
data Monomial = Monomial
{ m_coeff :: Coefficient
, m_powers :: [(Variable, Power)]
}
deriving ()
instance Ord Monomial where
(>=) = on (>=) m_powers
instance Eq Monomial where
(==) = on (==) m_powers
This is an excerpt from my code, reduced to the main size. Try to compare:
*Main> (Monomial 1 [("x",2)]) > (Monomial (-1) [])
*Main> (Monomial 1 [("x",2)]) < (Monomial (-1) [])
On the side of the note, it’s interesting that if I replaced the s/(>=)/(>)/ginstance in the declaration, it will not hang on the first pair, but it will still be on the second:
*Main> (Monomial 1 [("x",2)]) > (Monomial (-1) [])
True
*Main> (Monomial 1 [("x",2)]) < (Monomial (-1) [])
Although the standard state, the minimum declaration Eq instanceshould be either $compare$or $(>=)$.
What could be the problem? (> =) on lists seems to work fine.
source
share