th-alpha 0.1.0.0 → 0.1.0.1
raw patch · 2 files changed
+37/−14 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- src/Language/Haskell/TH/Alpha.hs +21/−6
- th-alpha.cabal +16/−8
src/Language/Haskell/TH/Alpha.hs view
@@ -17,13 +17,19 @@ This can be useful when for instance testing libraries that use Template Haskell: usually correctness is only defined up to alpha equivalence. +For most cases, 'areExpEq' is the only function you'll need. The 'AlphaEq'+class is only exported to make it easier to expand alpha-equality+comparison to other instances, or to be used (in combination with the+package __th-desugar__) for alpha equality comparisons of non-expression+types (e.g. TyVarBndr).+ /N.B.:/ This package doesn't yet handle type annotations correctly! -} module Language.Haskell.TH.Alpha (- AlphaEq(..),+ areExpEq, exp_equal,- areExpEq+ AlphaEq(..) ) where import Language.Haskell.TH@@ -35,6 +41,7 @@ import Data.Maybe (isJust) + -- A poor man's bound variable lookup table. type Lookup = ([(Name,Int)], [(Name,Int)], Int) @@ -55,15 +62,23 @@ --------------------------------------------------------------------------- -- Exp ---------------------------------------------------------------------------++-- | Convenience function that uses 'runQ' on 'exp_equal'.+--+-- >>> areExpEq [| let x = 5 in x |] [| let y = 5 in y |]+-- True+areExpEq :: Quasi m+ => ExpQ -- ^ Quoted expression+ -> ExpQ -- ^ Quoted expression+ -> m Bool+areExpEq e1 e2 = let expM = (join .) . liftM2 exp_equal+ in expM (runQ e1) (runQ e2)+ -- | Compare two expressions for alpha-equivalence. Since this uses -- th-desugar to desugar the expressions, returns a Bool in the Quasi -- context. exp_equal :: Quasi m => Exp -> Exp -> m Bool exp_equal t1 t2 = (liftM3 exp_equal') (dsExp t1) (dsExp t2) (return ([], [], 0))--areExpEq :: Quasi m => ExpQ -> ExpQ -> m Bool-areExpEq e1 e2 = let expM = (join .) . liftM2 exp_equal- in expM (runQ e1) (runQ e2) instance AlphaEq DExp where lkEq a b lk = if exp_equal' a b lk then Just lk else Nothing
th-alpha.cabal view
@@ -2,23 +2,31 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: th-alpha-version: 0.1.0.0-synopsis: Alpha equivalence for TH Dec and Exp--- description: +version: 0.1.0.1+synopsis: Alpha equivalence for TH Exp+description: + Compare TH expressions (or clauses, patterns, etc.) for alpha equivalence.+ That is, compare for equality modulo the renaming of bound variables.+ .+ >>> areExpEq [| \x -> x |] [| \y -> y |]+ True+ .+ This can be useful when for instance testing libraries that use Template + Haskell - usually correctness is only defined up to alpha equivalence. license: BSD3 license-file: LICENSE author: Julian K. Arni-maintainer: jkarni@gmail.com--- copyright: +maintainer: Julian K. Arni <jkarni@gmail.com>+copyright: Julian K. Arni category: Language build-type: Simple--- extra-source-files: cabal-version: >=1.10+stability: alpha+homepage: https://github.com/jkarni/th-alpha+bug-reports: https://github.com/jkarni/th-alpha/issues library exposed-modules: Language.Haskell.TH.Alpha- -- other-modules: - -- other-extensions: build-depends: base >=4 && <5 , template-haskell , th-desugar