Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Created March 4, 2014 21:16
Show Gist options
  • Select an option

  • Save pedrofurla/9355837 to your computer and use it in GitHub Desktop.

Select an option

Save pedrofurla/9355837 to your computer and use it in GitHub Desktop.
A very humble usage of SYB (so far)
isIdent :: String -> Ident -> Bool
isIdent s (Ident id') = id' == s
isIdentG :: forall a. Typeable a => String -> a -> Bool
isIdentG s = False `mkQ` (isIdent s)
{-| One level search of `Ident`s -}
withId1 :: forall a. Data a => String -> a -> Bool
withId1 s = or . (gmapQ (isIdentG s)) -- This saves me from matching against 7 different constructors
{-| Search a given `Ident` on all levels -}
withId :: forall a. Data a => String -> a -> Bool
withId s = everything (||) (isIdentG s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment