File: ExtraG.hs

package info (click to toggle)
haskell-set-extra 1.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 60 kB
  • sloc: haskell: 101; makefile: 2
file content (18 lines) | stat: -rw-r--r-- 620 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
module Data.Set.ExtraG 
    ( gFind
    ) where

import Data.Generics hiding (GT)
import Control.Monad.Reader
import Data.Set (Set, fromList)

gFind :: forall a b. (Data a, Typeable b, Ord b) => a -> Set b
gFind x = fromList (gFind' x :: [b])

-- | @gFind a@ will extract any elements of type @b@ from
-- @a@'s structure in accordance with the MonadPlus
-- instance, e.g. Maybe Foo will return the first Foo
-- found while [Foo] will return the list of Foos found.
gFind' :: (MonadPlus m, Data a, Typeable b) => a -> m b
gFind' = msum . map return . listify (const True)