On Friday 21 May 2010 19:06:51, R J wrote:
> Why does the following, trivial code snippet below hang GHCi when I
> type"Scalene > Failure", and what's the fix?
For an Ord instance, you need to define at least one of compare and (<=) or
the other functions from the class won't work.
All methods h
From Prelude.hs:
class (Eq a) => Ord a where
compare :: a -> a -> Ordering
(<), (<=), (>), (>=) :: a -> a -> Bool
max, min :: a -> a -> a
compare x y = if x == y then EQ
-- NB: must be '<=' not '<' to validate the
--
2010/5/21 R J :
> Why does the following, trivial code snippet below hang GHCi when I type
> "Scalene > Failure", and what's the fix?
An instance of Ord must declare compare or (<=). You only defined (<),
so (>) is using the default definition. Here are the defaults:
compare x y = if x == y
Why does the following, trivial code snippet below hang GHCi when I
type"Scalene > Failure", and what's the fix?
data Triangle = Failure |
Equilateral | Isosceles
| Scalene