Commit 0a8e8995 authored by David Feuer's avatar David Feuer Committed by Herbert Valerio Riedel

Remove redundant contexts from Foldable methods

New `Foldable` methods accidentally had `Foldable` contexts, which led
to type roles being assigned incorrectly and preventing GND from
deriving `Foldable` instances. Removing those fixes #9761.

Moreover, this patch takes advantage of this fix by deriving
`Foldable` (and `Eq`) for `UniqFM`.

Differential Revision: https://phabricator.haskell.org/D425
parent 77f82211
......@@ -72,7 +72,6 @@ import Outputable
import Compiler.Hoopl hiding (Unique)
import Data.Function (on)
import qualified Data.IntMap as M
import qualified Data.IntSet as S
import qualified Data.Foldable as Foldable
......@@ -212,22 +211,9 @@ instance Monoid (UniqFM a) where
%************************************************************************
\begin{code}
newtype UniqFM ele = UFM { unUFM :: M.IntMap ele }
deriving (Typeable,Data, Traversable.Traversable, Functor)
instance Eq ele => Eq (UniqFM ele) where
(==) = (==) `on` unUFM
{-
instance Functor UniqFM where
fmap f = fmap f . unUFM
instance Traversable.Traversable UniqFM where
traverse f = Traversable.traverse f . unUFM
-}
instance Foldable.Foldable UniqFM where
foldMap f = Foldable.foldMap f . unUFM
newtype UniqFM ele = UFM (M.IntMap ele)
deriving (Data, Eq, Foldable.Foldable, Functor, Traversable.Traversable,
Typeable)
emptyUFM = UFM M.empty
isNullUFM (UFM m) = M.null m
......
......@@ -145,28 +145,28 @@ class Foldable t where
Just x -> f x y)
-- | List of elements of a structure.
toList :: Foldable t => t a -> [a]
toList :: t a -> [a]
{-# INLINE toList #-}
toList t = build (\ c n -> foldr c n t)
-- | Test whether the structure is empty.
null :: Foldable t => t a -> Bool
null :: t a -> Bool
null = foldr (\_ _ -> False) True
-- | Returns the size/length of a finite structure as an 'Int'.
length :: Foldable t => t a -> Int
length :: t a -> Int
length = foldl' (\c _ -> c+1) 0
-- | Does the element occur in the structure?
elem :: (Foldable t, Eq a) => a -> t a -> Bool
elem :: Eq a => a -> t a -> Bool
elem = any . (==)
-- | The largest element of a non-empty structure.
maximum :: (Foldable t, Ord a) => t a -> a
maximum :: Ord a => t a -> a
maximum = foldr1 max
-- | The least element of a non-empty structure.
minimum :: (Foldable t, Ord a) => t a -> a
minimum :: Ord a => t a -> a
minimum = foldr1 min
-- | The 'sum' function computes the sum of the numbers of a structure.
......@@ -175,7 +175,7 @@ class Foldable t where
-- | The 'product' function computes the product of the numbers of a
-- structure.
product :: (Foldable t, Num a) => t a -> a
product :: Num a => t a -> a
product = getProduct . foldMap Product
-- instances for Prelude types
......
......@@ -53,8 +53,7 @@ class Eq a where
(GHC.Classes./=) :: a -> a -> GHC.Types.Bool
-- imported via Prelude, T
Prelude.length ::
Data.Foldable.Foldable t =>
forall a. Data.Foldable.Foldable t => t a -> GHC.Types.Int
Data.Foldable.Foldable t => forall a. t a -> GHC.Types.Int
-- imported via T
data T.Integer
= integer-gmp-0.5.1.0:GHC.Integer.Type.S# GHC.Prim.Int#
......
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