notcpp-0.0.1: Avoiding the C preprocessor via cunning use of Template Haskell

Safe HaskellNone



This module exports scopeLookup, which will find a variable or value constructor for you and present it for your use. E.g. at some point in the history of the acid-state package, openAcidState was renamed openLocalState; for compatibility with both, you could use:

 openState :: IO (AcidState st)
 openState = case $(scopeLookup "openLocalState") of
   Just open -> open defaultState
   Nothing -> case $(scopeLookup "openAcidState") of
     Just open -> open defaultState
     Nothing -> error
       "openState: runtime name resolution has its drawbacks :/"



scopeLookup :: String -> Q ExpSource

Produces a spliceable expression which expands to 'Just val' if the given string refers to a value val in scope, or Nothing otherwise.

maybeReify :: Name -> Q (Maybe Info)Source

A useful variant of reify that returns Nothing instead of halting compilation when an error occurs (e.g. because the given name was not in scope).