th-alpha-0.1.0.1: Alpha equivalence for TH Exp

Stabilityexperimental
Maintainerjkarni@gmail.com
Safe HaskellNone

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.

>>> 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.

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!

Synopsis

Documentation

areExpEqSource

Arguments

:: Quasi m 
=> ExpQ

Quoted expression

-> ExpQ

Quoted expression

-> m Bool 

Convenience function that uses runQ on exp_equal.

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

exp_equal :: Quasi m => Exp -> Exp -> m BoolSource

Compare two expressions for alpha-equivalence. Since this uses th-desugar to desugar the expressions, returns a Bool in the Quasi context.

class AlphaEq a whereSource

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.

Methods

(@=) :: a -> a -> BoolSource

Compares its arguments for alpha equivalence.

lkEq :: a -> a -> Lookup -> Maybe LookupSource

Given a variable binding lookup compares arguments for alpha equivalence, returning Just of updated lookup in case of equivalence, Nothing otherwise.