monadloc 0.6 → 0.7
raw patch · 3 files changed
+44/−33 lines, 3 files
Files
- Control/Monad/Loc.hs +6/−30
- Control/Monad/Loc/TH.hs +33/−0
- monadloc.cabal +5/−3
Control/Monad/Loc.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE CPP #-}+#if defined(__GLASGOW_HASKELL__) && (__GLASGOW_HASKELL__ >= 702)+{-# LANGUAGE Safe #-}+#endif {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE FlexibleInstances #-}@@ -16,13 +19,9 @@ { -\# OPTIONS_GHC -F -pgmF MonadLoc \#- } @ - * There is also the TH macro 'withLocTH' to manually annotate program points,- but you should always use the preprocessor if possible.+ * There is also the TH macro 'withLocTH' exported by "Control.Monad.Loc.TH" -}-module Control.Monad.Loc (MonadLoc(..), withLocTH) where-import Language.Haskell.TH.Syntax (qLocation, Loc(..), Q, Exp)-import Prelude hiding (mod)-import Text.Printf+module Control.Monad.Loc (MonadLoc(..)) where -- | Generating stack traces for failures class Monad m => MonadLoc m where@@ -32,26 +31,3 @@ withLoc :: String -> m a -> m a instance Monad m => MonadLoc m where withLoc _ = id;----- | 'withLocTH' is a convenient TH macro which expands to 'withLoc' @\<source location\>@--- It should only be used when the MonadLoc preprocessor is not available.--- Usage:------ > f x = $withLocTH $ do--- > $withLocTH $ something--- > x < -$withLocTH $ something-else--- > ...------ NOTE: unfortunately type signatures are necessary when using withLocTH--withLocTH :: Q Exp-withLocTH = do- loc <- qLocation- let loc_msg = showLoc loc- [| withLoc loc_msg |]--showLoc :: Loc -> String-showLoc Loc{loc_module=mod, loc_filename=filename, loc_start=start} =- {- text package <> char '.' <> -}- printf "%s (%s). %s" mod filename (show start)
+ Control/Monad/Loc/TH.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE TemplateHaskell #-}++-- | The TH macro 'withLocTH' to manually annotate program points,+-- but you should always use the preprocessor if possible.++module Control.Monad.Loc.TH (withLocTH) where++import Prelude hiding (mod)+import Language.Haskell.TH.Syntax (qLocation, Loc(..), Q, Exp)+import Text.Printf+import Control.Monad.Loc++-- | 'withLocTH' is a convenient TH macro which expands to 'withLoc' @\<source location\>@+-- It should only be used when the MonadLoc preprocessor is not available.+-- Usage:+--+-- > f x = $withLocTH $ do+-- > $withLocTH $ something+-- > x < -$withLocTH $ something-else+-- > ...+--+-- NOTE: unfortunately type signatures are necessary when using withLocTH++withLocTH :: Q Exp+withLocTH = do+ loc <- qLocation+ let loc_msg = showLoc loc+ [| withLoc loc_msg |]++showLoc :: Loc -> String+showLoc Loc{loc_module=mod, loc_filename=filename, loc_start=start} =+ {- text package <> char '.' <> -}+ printf "%s (%s). %s" mod filename (show start)
monadloc.cabal view
@@ -1,5 +1,5 @@ name: monadloc-version: 0.6+version: 0.7 Cabal-Version: >= 1.6 build-type: Simple license: PublicDomain@@ -8,7 +8,7 @@ homepage: http://github.com/pepeiborra/monadloc synopsis: A class for monads which can keep a monadic call trace category: Control, Monads-stability: experimental+stability: provisional description: This package defines a class for monads which can keep a monadic call trace. .@@ -24,6 +24,8 @@ /Changes/: .+ * 0.7 - Extracted Template Haskell macro to separate module to allow @Control.Monad.Loc@ to be Safe. (thanks to Deian Stefan)+ . * 0.6 - Extracted the preprocessor to a separate package @monadloc-pp@ to minimize the set of dependencies. Library@@ -31,9 +33,9 @@ build-depends: base >= 4 && < 5, template-haskell, transformers ghc-options: -Wall -fno-warn-orphans- extensions: FlexibleInstances, OverlappingInstances, UndecidableInstances, TemplateHaskell, PatternGuards exposed-modules: Control.Monad.Loc+ Control.Monad.Loc.TH Control.Monad.Loc.Transformers source-repository head