summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2016-11-29 14:45:19 -0500
committerBen Gamari <ben@smart-cactus.org>2016-11-29 14:45:19 -0500
commiteaed140c438255263b984d73f66483a76ef5474e (patch)
tree60dfd1f1775b079d43056978b2d1d826de228390 /compiler/utils
parent6d5c2e7b428844a8ff80245579c980c015e6b7e8 (diff)
downloadhaskell-eaed140c438255263b984d73f66483a76ef5474e.tar.gz
OrdList: Add Foldable, Traversable instances
Test Plan: Validate Reviewers: austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2740
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/OrdList.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/utils/OrdList.hs b/compiler/utils/OrdList.hs
index 625886d0a7..3c5b9d7380 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