diff options
author | RyanGlScott <ryan.gl.scott@gmail.com> | 2016-02-25 14:49:48 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-02-25 15:41:55 +0100 |
commit | 673efccb3b348e9daf23d9e65460691bbea8586e (patch) | |
tree | 825b41d829a0e032a2db18386edd5a39036c2dc2 /libraries/base/Data/Foldable.hs | |
parent | 6319a8cf79cc1f1e25220113149ab48e5083321b (diff) | |
download | haskell-673efccb3b348e9daf23d9e65460691bbea8586e.tar.gz |
Add more type class instances for GHC.Generics
GHC.Generics provides several representation data types that have
obvious instances of various type classes in base, along with various
other types of meta-data (such as associativity and fixity).
Specifically, instances have been added for the following type classes
(where possible):
- Applicative
- Data
- Functor
- Monad
- MonadFix
- MonadPlus
- MonadZip
- Foldable
- Traversable
- Enum
- Bounded
- Ix
- Generic1
Thanks to ocharles for starting this!
Test Plan: Validate
Reviewers: ekmett, austin, hvr, bgamari
Reviewed By: bgamari
Subscribers: RyanGlScott, thomie
Differential Revision: https://phabricator.haskell.org/D1937
GHC Trac Issues: #9043
Diffstat (limited to 'libraries/base/Data/Foldable.hs')
-rw-r--r-- | libraries/base/Data/Foldable.hs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index 3d518d5c4b..5d758ae691 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -1,6 +1,10 @@ -{-# LANGUAGE Trustworthy #-} +{-# LANGUAGE DeriveFoldable #-} +{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE Trustworthy #-} +{-# LANGUAGE TypeOperators #-} ----------------------------------------------------------------------------- -- | @@ -61,6 +65,7 @@ import GHC.Arr ( Array(..), elems, numElements, foldlElems', foldrElems', foldl1Elems, foldr1Elems) import GHC.Base hiding ( foldr ) +import GHC.Generics import GHC.Num ( Num(..) ) infix 4 `elem`, `notElem` @@ -419,6 +424,23 @@ instance Ord a => Monoid (Min a) where | x <= y = Min m | otherwise = Min n +-- Instances for GHC.Generics +deriving instance Foldable V1 +deriving instance Foldable U1 +deriving instance Foldable Par1 +deriving instance Foldable f => Foldable (Rec1 f) +deriving instance Foldable (K1 i c) +deriving instance Foldable f => Foldable (M1 i c f) +deriving instance (Foldable f, Foldable g) => Foldable (f :+: g) +deriving instance (Foldable f, Foldable g) => Foldable (f :*: g) +deriving instance (Foldable f, Foldable g) => Foldable (f :.: g) +deriving instance Foldable UAddr +deriving instance Foldable UChar +deriving instance Foldable UDouble +deriving instance Foldable UFloat +deriving instance Foldable UInt +deriving instance Foldable UWord + -- | Monadic fold over the elements of a structure, -- associating to the right, i.e. from right to left. foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b |