summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Traversable.hs
diff options
context:
space:
mode:
authorRyanGlScott <ryan.gl.scott@gmail.com>2016-02-25 14:49:48 +0100
committerBen Gamari <ben@smart-cactus.org>2016-02-25 15:41:55 +0100
commit673efccb3b348e9daf23d9e65460691bbea8586e (patch)
tree825b41d829a0e032a2db18386edd5a39036c2dc2 /libraries/base/Data/Traversable.hs
parent6319a8cf79cc1f1e25220113149ab48e5083321b (diff)
downloadhaskell-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/Traversable.hs')
-rw-r--r--libraries/base/Data/Traversable.hs24
1 files changed, 23 insertions, 1 deletions
diff --git a/libraries/base/Data/Traversable.hs b/libraries/base/Data/Traversable.hs
index 9da76c6a34..c6a30d7213 100644
--- a/libraries/base/Data/Traversable.hs
+++ b/libraries/base/Data/Traversable.hs
@@ -1,5 +1,9 @@
-{-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE DeriveTraversable #-}
+{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE TypeOperators #-}
-----------------------------------------------------------------------------
-- |
@@ -58,6 +62,7 @@ import Data.Proxy ( Proxy(..) )
import GHC.Arr
import GHC.Base ( Applicative(..), Monad(..), Monoid, Maybe(..),
($), (.), id, flip )
+import GHC.Generics
import qualified GHC.List as List ( foldr )
-- | Functors representing data structures that can be traversed from
@@ -222,6 +227,23 @@ instance Traversable Last where
instance Traversable ZipList where
traverse f (ZipList x) = ZipList <$> traverse f x
+-- Instances for GHC.Generics
+deriving instance Traversable V1
+deriving instance Traversable U1
+deriving instance Traversable Par1
+deriving instance Traversable f => Traversable (Rec1 f)
+deriving instance Traversable (K1 i c)
+deriving instance Traversable f => Traversable (M1 i c f)
+deriving instance (Traversable f, Traversable g) => Traversable (f :+: g)
+deriving instance (Traversable f, Traversable g) => Traversable (f :*: g)
+deriving instance (Traversable f, Traversable g) => Traversable (f :.: g)
+deriving instance Traversable UAddr
+deriving instance Traversable UChar
+deriving instance Traversable UDouble
+deriving instance Traversable UFloat
+deriving instance Traversable UInt
+deriving instance Traversable UWord
+
-- general functions
-- | 'for' is 'traverse' with its arguments flipped. For a version