我目前正在学习如何编写类型类.我似乎无法编写具有模糊发生的编译错误的Ord类型类.
module Practice where
class (Eq a) => Ord a where
compare :: a -> a -> Ordering
(<), (<=), (>=), (>) :: a -> a -> Bool
max, min :: a -> a -> a
-- Minimal complete definition:
-- (<=) or compare
-- Using compare can be more efficient for complex types.
compare x y
| x == y = EQ
| x <= y = LT
| otherwise = GT
x <= y = compare x y …Run Code Online (Sandbox Code Playgroud)