aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src
diff options
context:
space:
mode:
authorƁukasz Hanuszczak <lukasz.hanuszczak@gmail.com>2015-07-10 12:24:12 +0200
committerMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2015-08-21 18:22:29 +0100
commitdc25b7099a0d54c03bdf51dfb9a4e286942d9c31 (patch)
tree435ebaca235acaceaa50b78255e1320cffd2b8ca /haddock-api/src
parentf7d377ee238d3b44240a4537986a7561e822f79f (diff)
Implement generic transformation constructor.
Diffstat (limited to 'haddock-api/src')
-rw-r--r--haddock-api/src/Haddock/Syb.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/haddock-api/src/Haddock/Syb.hs b/haddock-api/src/Haddock/Syb.hs
index 3cec724e..2016b74c 100644
--- a/haddock-api/src/Haddock/Syb.hs
+++ b/haddock-api/src/Haddock/Syb.hs
@@ -3,6 +3,7 @@
module Haddock.Syb
( everything, everywhere
+ , mkT
, combine
) where
@@ -25,6 +26,14 @@ everything k f x = foldl k (f x) (gmapQ (everything k f) x)
everywhere :: (forall a. Data a => a -> a) -> (forall a. Data a => a -> a)
everywhere f = f . gmapT (everywhere f)
+-- | Create generic transformation.
+--
+-- Another function stolen from SYB package.
+mkT :: (Typeable a, Typeable b) => (b -> b) -> (a -> a)
+mkT f = case cast f of
+ Just f' -> f'
+ Nothing -> id
+
-- | Combine two queries into one using alternative combinator.
combine :: Alternative f => (forall a. Data a => a -> f r)
-> (forall a. Data a => a -> f r)