[commit: ghc] master: OrdList: Add Foldable, Traversable instances (eaed140)

git at git.haskell.org git at git.haskell.org
Tue Nov 29 21:38:08 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/eaed140c438255263b984d73f66483a76ef5474e/ghc

>---------------------------------------------------------------

commit eaed140c438255263b984d73f66483a76ef5474e
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Tue Nov 29 14:45:19 2016 -0500

    OrdList: Add Foldable, Traversable instances
    
    Test Plan: Validate
    
    Reviewers: austin, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2740


>---------------------------------------------------------------

eaed140c438255263b984d73f66483a76ef5474e
 compiler/utils/OrdList.hs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/compiler/utils/OrdList.hs b/compiler/utils/OrdList.hs
index 625886d..3c5b9d7 100644
--- a/compiler/utils/OrdList.hs
+++ b/compiler/utils/OrdList.hs
@@ -49,6 +49,15 @@ instance Monoid (OrdList a) where
   mappend = appOL
   mconcat = concatOL
 
+instance Functor OrdList where
+  fmap = mapOL
+
+instance Foldable OrdList where
+  foldr = foldrOL
+
+instance Traversable OrdList where
+  traverse f xs = toOL <$> traverse f (fromOL xs)
+
 nilOL    :: OrdList a
 isNilOL  :: OrdList a -> Bool
 
@@ -98,9 +107,6 @@ mapOL f (Snoc xs x) = Snoc (mapOL f xs) (f x)
 mapOL f (Two x y) = Two (mapOL f x) (mapOL f y)
 mapOL f (Many xs) = Many (map f xs)
 
-instance Functor OrdList where
-  fmap = mapOL
-
 foldrOL :: (a->b->b) -> b -> OrdList a -> b
 foldrOL _ z None        = z
 foldrOL k z (One x)     = k x z



More information about the ghc-commits mailing list