diff options
author | Ćukasz Hanuszczak <lukasz.hanuszczak@gmail.com> | 2015-07-10 11:42:18 +0200 |
---|---|---|
committer | Mateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk> | 2015-08-21 18:22:29 +0100 |
commit | e9d61b79faf40200d8f9806d83a05ece272cd7d3 (patch) | |
tree | d11c049d80dc6070edc0a034caf3b42e02636c03 /haddock-api/src/Haddock/Syb.hs | |
parent | 81baac997afa74be86f215d830322455b879f791 (diff) |
Move SYB utilities to standalone module.
Diffstat (limited to 'haddock-api/src/Haddock/Syb.hs')
-rw-r--r-- | haddock-api/src/Haddock/Syb.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/haddock-api/src/Haddock/Syb.hs b/haddock-api/src/Haddock/Syb.hs new file mode 100644 index 00000000..dd7ffc1b --- /dev/null +++ b/haddock-api/src/Haddock/Syb.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE Rank2Types #-} + + +module Haddock.Syb + ( everything + , combine + ) where + + +import Data.Data +import Control.Applicative + + +-- | Perform a query on each level of a tree. +-- +-- This is stolen directly from SYB package and copied here to not introduce +-- additional dependencies. +everything :: (r -> r -> r) -> (forall a. Data a => a -> r) + -> (forall a. Data a => a -> r) +everything k f x = foldl k (f x) (gmapQ (everything k f) x) + +-- | 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) + -> (forall a. Data a => a -> f r) +combine f g x = f x <|> g x |