diff options
author | RyanGlScott <ryan.gl.scott@gmail.com> | 2016-02-29 12:28:18 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-02-29 13:42:02 +0100 |
commit | 171d95df24dc2d9d0c1a3af9e75f021438a7da50 (patch) | |
tree | 0a587d60a22eed012b7a35f2a053a8017b70cdf2 /libraries/base/Data/Foldable.hs | |
parent | 46f3775c683faeb710c9dc22f360f39334947d73 (diff) | |
download | haskell-171d95df24dc2d9d0c1a3af9e75f021438a7da50.tar.gz |
Missing Proxy instances, make U1 instance more Proxy-like
This accomplishes three things:
* Adds missing `Alternative`, `MonadPlus`, and `MonadZip` instances for
`Proxy`
* Adds a missing `MonadPlus` instance for `U1`
* Changes several existing `U1` instances to use lazy pattern-matching,
exactly how `Proxy` does it (in case we ever replace `U1` with
`Proxy`). This is technically a breaking change (albeit an extremely
minor one).
Test Plan: ./validate
Reviewers: austin, ekmett, hvr, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1962
GHC Trac Issues: #11650
Diffstat (limited to 'libraries/base/Data/Foldable.hs')
-rw-r--r-- | libraries/base/Data/Foldable.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index 5d758ae691..0defe6c07c 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -425,8 +425,24 @@ instance Ord a => Monoid (Min a) where | otherwise = Min n -- Instances for GHC.Generics +instance Foldable U1 where + foldMap _ _ = mempty + {-# INLINE foldMap #-} + fold _ = mempty + {-# INLINE fold #-} + foldr _ z _ = z + {-# INLINE foldr #-} + foldl _ z _ = z + {-# INLINE foldl #-} + foldl1 _ _ = errorWithoutStackTrace "foldl1: U1" + foldr1 _ _ = errorWithoutStackTrace "foldr1: U1" + length _ = 0 + null _ = True + elem _ _ = False + sum _ = 0 + product _ = 1 + 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) |