I am currently learning how to write type classes. I canβt write a class like Ord with ambiguous compilation errors.
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 xy | x == y = EQ | x <= y = LT | otherwise = GT x <= y = compare xy /= GT x < y = compare xy == LT x >= y = compare xy /= LT x > y = compare xy == GT -- note that (min xy, max xy) = (x,y) or (y,x) max xy | x <= y = y | otherwise = x min xy | x <= y = x | otherwise = y
Mistakes
Practice.hs:26:14: Ambiguous occurrence `<=' It could refer to either `Practice.<=', defined at Practice.hs:5:10 or `Prelude.<=', imported from `Prelude' at Practice.hs:1:8-15 ...
etc. I think it is facing a specific version of Prelude.
user1850254
source share