From dc25b7099a0d54c03bdf51dfb9a4e286942d9c31 Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Fri, 10 Jul 2015 12:24:12 +0200 Subject: Implement generic transformation constructor. --- haddock-api/src/Haddock/Syb.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'haddock-api/src/Haddock') 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) -- cgit v1.2.3