th-alpha-0.2.1.0: Alpha equivalence for TH Exp

Copyright(c) Julian K. Arni 2014
LicenseBSD3
Maintainerjkarni@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Alpha

Description

Compare TH expressions (or clauses, patterns, etc.) for alpha equivalence. That is, compare for equality modulo the renaming of bound variables.

>>> areExpAEq [| \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.

For most cases, areExpAEq 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!

Synopsis

Documentation

areExpAEq Source #

Arguments

:: DsMonad m 
=> ExpQ

Quoted expression

-> ExpQ

Quoted expression

-> m Bool 

Convenience function that uses runQ on expEqual.

>>> areExpAEq [| let x = 5 in x |] [| let y = 5 in y |]
True

expEqual :: DsMonad m => Exp -> Exp -> m Bool Source #

(@=) :: (Monad m, AlphaEq a m) => a -> a -> m Bool infix 4 Source #

Compares its arguments for alpha equivalence. The default implementation uses Lookup for its LookupTbl, but more efficient datatypes can be used.

class AlphaEq a m | a -> m where Source #

The main Alpha Equivalence class. @= is by default defined in terms of lkEq. lkEq is exposed for composability: it is easy to recursively build AlphaEq instances from other AlphaEq instances by delegating the lookup update to the subinstances.

Minimal complete definition

lkEq

Methods

lkEq :: a -> a -> LookupSTM m () Source #

Given a variable binding lookup compares arguments for alpha equivalence, setting the state to Just of updated lookup in case of equivalence, Nothing otherwise.

Instances

AlphaEq Exp Q Source # 

Methods

lkEq :: Exp -> Exp -> LookupSTM Q () Source #

AlphaEq DExp Identity Source # 

Methods

lkEq :: DExp -> DExp -> LookupSTM Identity () Source #

AlphaEq DPat Identity Source # 

Methods

lkEq :: DPat -> DPat -> LookupSTM Identity () Source #

AlphaEq DType Identity Source # 

Methods

lkEq :: DType -> DType -> LookupSTM Identity () Source #

AlphaEq DPred Identity Source # 

Methods

lkEq :: DPred -> DPred -> LookupSTM Identity () Source #

AlphaEq DMatch Identity Source # 

Methods

lkEq :: DMatch -> DMatch -> LookupSTM Identity () Source #

AlphaEq DClause Identity Source # 

Methods

lkEq :: DClause -> DClause -> LookupSTM Identity () Source #

AlphaEq DLetDec Identity Source # 

Methods

lkEq :: DLetDec -> DLetDec -> LookupSTM Identity () Source #