Commit b214e7a3 authored by Ian Lynagh's avatar Ian Lynagh

Fix more tests following the removal of Num's superclasses

parent c5eed726
...@@ -7,7 +7,7 @@ import T2902_Sum ...@@ -7,7 +7,7 @@ import T2902_Sum
data PSum a b = Empty | Tree a b [(PSum a b)] data PSum a b = Empty | Tree a b [(PSum a b)]
instance (Ord a, Num b) Sum PSum a b where instance (Ord a, Eq b, Num b) Sum PSum a b where
insert = insertX insert = insertX
union = unionX union = unionX
unions = unionsX unions = unionsX
...@@ -15,10 +15,10 @@ instance (Ord a, Num b) ⇒ Sum PSum a b where ...@@ -15,10 +15,10 @@ instance (Ord a, Num b) ⇒ Sum PSum a b where
fromList = fromListX fromList = fromListX
toList = toListX toList = toListX
insertX (Ord a, Num b) a b PSum a b PSum a b insertX (Ord a, Eq b, Num b) a b PSum a b PSum a b
insertX v r = unionX $ Tree v r [] insertX v r = unionX $ Tree v r []
unionX (Ord a, Num b) PSum a b PSum a b PSum a b unionX (Ord a, Eq b, Num b) PSum a b PSum a b PSum a b
unionX x Empty = x unionX x Empty = x
unionX Empty x = x unionX Empty x = x
unionX x@(Tree v r xs) y@(Tree w s ys) = unionX x@(Tree v r xs) y@(Tree w s ys) =
...@@ -30,20 +30,20 @@ unionX x@(Tree v r xs) y@(Tree w s ys) = ...@@ -30,20 +30,20 @@ unionX x@(Tree v r xs) y@(Tree w s ys) =
t insertX v t z t insertX v t z
where z = unionX (unionsX xs) (unionsX ys) where z = unionX (unionsX xs) (unionsX ys)
unionsX (Ord a, Num b) [PSum a b] PSum a b unionsX (Ord a, Eq b, Num b) [PSum a b] PSum a b
unionsX [] = Empty unionsX [] = Empty
unionsX [x] = x unionsX [x] = x
unionsX (x : y : zs) = unionX (unionX x y) (unionsX zs) unionsX (x : y : zs) = unionX (unionX x y) (unionsX zs)
extractMinX (Ord a, Num b) PSum a b ((a,b), PSum a b) extractMinX (Ord a, Eq b, Num b) PSum a b ((a,b), PSum a b)
extractMinX Empty = undefined extractMinX Empty = undefined
extractMinX (Tree v r xs) = ((v,r), unionsX xs) extractMinX (Tree v r xs) = ((v,r), unionsX xs)
fromListX (Ord a, Num b) [(a,b)] PSum a b fromListX (Ord a, Eq b, Num b) [(a,b)] PSum a b
fromListX [] = Empty fromListX [] = Empty
fromListX ((v,r):xs) = insertX v r $ fromListX xs fromListX ((v,r):xs) = insertX v r $ fromListX xs
toListX (Ord a, Num b) PSum a b [(a,b)] toListX (Ord a, Eq b, Num b) PSum a b [(a,b)]
toListX Empty = [] toListX Empty = []
toListX x = let (y, z) = extractMinX x in y : toListX z toListX x = let (y, z) = extractMinX x in y : toListX z
...@@ -7,7 +7,7 @@ import T2902_Sum ...@@ -7,7 +7,7 @@ import T2902_Sum
data PSum a b = Empty | Tree a b [PSum a b] data PSum a b = Empty | Tree a b [PSum a b]
instance (Ord a, Num b) Sum PSum a b where instance (Ord a, Eq b, Num b) Sum PSum a b where
insert v r = union $ Tree v r [] insert v r = union $ Tree v r []
......
...@@ -8,11 +8,11 @@ module T4203 where ...@@ -8,11 +8,11 @@ module T4203 where
newtype NonNegative a = NonNegative a newtype NonNegative a = NonNegative a
deriving (Eq, Num, Show) deriving (Eq, Num, Show)
instance Num a => Arbitrary (NonNegative a) where instance (Eq a, Num a) => Arbitrary (NonNegative a) where
arbitrary = return (rubble (rubble 0)) arbitrary = return (rubble (rubble 0))
coarbitrary = error "urk" coarbitrary = error "urk"
rubble :: Num a => a -> a rubble :: (Eq a, Num a) => a -> a
rubble 0 = 1 rubble 0 = 1
rubble n = n * rubble (n-1) rubble n = n * rubble (n-1)
......
...@@ -19,7 +19,7 @@ instance MyClass Baz ...@@ -19,7 +19,7 @@ instance MyClass Baz
data Quux a = Quux a deriving Eq data Quux a = Quux a deriving Eq
data Quux2 a = Quux2 a deriving Eq data Quux2 a = Quux2 a deriving Eq
instance Eq a => MyClass (Quux a) instance Eq a => MyClass (Quux a)
instance Num a => MyClass (Quux2 a) instance Ord a => MyClass (Quux2 a)
class MyClass2 a b class MyClass2 a b
instance MyClass2 Int Bool instance MyClass2 Int Bool
......
...@@ -2,7 +2,7 @@ class GHC.Classes.Eq a_0 => Main.MyClass a_0 ...@@ -2,7 +2,7 @@ class GHC.Classes.Eq a_0 => Main.MyClass a_0
instance Main.MyClass Main.Foo instance Main.MyClass Main.Foo
instance Main.MyClass Main.Baz instance Main.MyClass Main.Baz
instance GHC.Classes.Eq a_1 => Main.MyClass (Main.Quux a_1) instance GHC.Classes.Eq a_1 => Main.MyClass (Main.Quux a_1)
instance GHC.Num.Num a_2 => Main.MyClass (Main.Quux2 a_2) instance GHC.Classes.Ord a_2 => Main.MyClass (Main.Quux2 a_2)
True True
True True
True True
......
...@@ -26,7 +26,7 @@ check empty = do ...@@ -26,7 +26,7 @@ check empty = do
out (pqSort empty [1 .. 99]) out (pqSort empty [1 .. 99])
out (pqSort empty [1.0, 1.1 ..99.9]) out (pqSort empty [1.0, 1.1 ..99.9])
out :: (Num a) => [a] -> IO () out :: (Eq a, Num a) => [a] -> IO ()
out x | sum x == 0 = putStr "ok\n" out x | sum x == 0 = putStr "ok\n"
| otherwise = putStr "ok\n" | otherwise = putStr "ok\n"
...@@ -64,7 +64,7 @@ instance Num a => Num (SubRange a) where ...@@ -64,7 +64,7 @@ instance Num a => Num (SubRange a) where
(*) = numSubRangeMultiply (*) = numSubRangeMultiply
fromInteger a = SubRange (fromInteger a, fromInteger a) (fromInteger a) fromInteger a = SubRange (fromInteger a, fromInteger a) (fromInteger a)
numSubRangeNegate :: (Ord a, Num a) => SubRange a -> SubRange a numSubRangeNegate :: (Ord a, Show a, Num a) => SubRange a -> SubRange a
numSubRangeNegate (SubRange (lower, upper) value) numSubRangeNegate (SubRange (lower, upper) value)
= checkRange (SubRange (lower, upper) (-value)) = checkRange (SubRange (lower, upper) (-value))
......
...@@ -29,22 +29,13 @@ tcfail067.hs:46:12: ...@@ -29,22 +29,13 @@ tcfail067.hs:46:12:
showRange (SubRange (lower, upper) value) showRange (SubRange (lower, upper) value)
= show value ++ " :" ++ show lower ++ ".." ++ show upper = show value ++ " :" ++ show lower ++ ".." ++ show upper
tcfail067.hs:60:10:
Could not deduce (Show (SubRange a))
arising from the superclasses of an instance declaration
from the context (Num a)
bound by the instance declaration at tcfail067.hs:60:10-34
Possible fix:
add (Show (SubRange a)) to the context of the instance declaration
or add an instance declaration for (Show (SubRange a))
In the instance declaration for `Num (SubRange a)'
tcfail067.hs:61:12: tcfail067.hs:61:12:
Could not deduce (Ord a) arising from a use of `numSubRangeNegate' Could not deduce (Ord a, Show a)
arising from a use of `numSubRangeNegate'
from the context (Num a) from the context (Num a)
bound by the instance declaration at tcfail067.hs:60:10-34 bound by the instance declaration at tcfail067.hs:60:10-34
Possible fix: Possible fix:
add (Ord a) to the context of the instance declaration add (Ord a, Show a) to the context of the instance declaration
In the expression: numSubRangeNegate In the expression: numSubRangeNegate
In an equation for `negate': negate = numSubRangeNegate In an equation for `negate': negate = numSubRangeNegate
In the instance declaration for `Num (SubRange a)' In the instance declaration for `Num (SubRange a)'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment