Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
This module contains a definition for a custom equality of IR AST nodes.
Two AST nodes are called similar
if they are equal modulo renaming
of bound variables. The source location information is also ignored.
Definition Renaming
A Renaming
is a mapping { x₁ ↦ y₁, …, xₙ ↦ yₙ }
from variables
x₁, …, xₙ
in one AST to variables y₁, …, yₙ
in another AST.
Note that variables and type variables are considered distict even
if they have the same name.
Definition: Free Variables in Renaming
A variable x
is leftFree
in a Renaming
Γ
if there is no
variable y
such that x ↦ y ∈ Γ
. Analogously a variable y
is
rightFree
in a Renaming
Γ
if there is no variable x
such
that x ↦ y ∈ Γ
. We write z ∈ free(Γ)
if z
is both leftFree
and rightFree
.
Notation
If two nodes n
and m
are similar under a Renaming
Γ
we write
Γ ⊢ n ≈ m
. Whether two nodes are equal or not can be determined
from the inference system described in the comments for the Similar
instances below.
Documentation
A type class for AST nodes that can be tested for similarity.
similar'
Instances
Similar Type Source # | The similarity relation of type expressions is governed by the the following inference rules.
|
Defined in FreeC.IR.Similar | |
Similar TypeScheme Source # | Two type schemes are similar if their abstracted types are similar
under an extend Γ ∪ { α₁ ↦ β₁, …, αₙ ↦ βₙ } ⊢ τ ≈ τ' ———————————————————————————————————————————— Γ ⊢ forall α₁ … αₙ. τ ≈ forall β₁ … βₙ. τ' |
Defined in FreeC.IR.Similar similar' :: TypeScheme -> TypeScheme -> Renaming -> Bool | |
Similar ConDecl Source # | Two constructor declarations are similar if their field types are similar. Γ ⊢ τ₁ ≈ τ'₁, …, Γ ⊢ τₙ ≈ τ'ₙ ——————————————————————————————— Γ ⊢ C τ₁ … τₙ ≈ C τ'₁ … τ'ₙ |
Defined in FreeC.IR.Similar | |
Similar TypeDecl Source # | Two type synonym declarations are similar if their right-hand sides are
similar under an extended Γ ∪ { α₁ ↦ β₁, …, αₙ ↦ βₙ } ⊢ τ ≈ τ' —————————————————————————————————————————————— Γ ⊢ type T α₁ … αₙ = τ ≈ type T β₁ … βₙ = τ' Two data type declarations are similar if their constructors are pairwise
similar under an extended Γ ∪ { α₁ ↦ β₁, …, αₙ ↦ βₙ } ⊢ con₁ ≈ con'₁, …, Γ ∪ { α₁ ↦ β₁, …, αₙ ↦ βₙ } ⊢ conₘ ≈ con'ₘ ———————————————————————————————————————————————————————————————————————— Γ ⊢ data D α₁ … αₙ = con₁ | … | conₘ ≈ data D β₁ … βₙ = con'₁ | … | con'ₘ |
Defined in FreeC.IR.Similar | |
Similar Pragma Source # | Two pragmas are similar if they are equal except for the source span. |
Defined in FreeC.IR.Similar | |
Similar Bind Source # | Two Γ' ⊢ p ≈ q , Γ' ⊢ e ≈ f —————————————————————————— Γ ⊢ p = e ≈ q = f |
Defined in FreeC.IR.Similar | |
Similar VarPat Source # | Two variable patterns are similar if they either both don't have a type annotation or are annotated with similar types. Γ ⊢ τ ≈ τ' ——————————— —————————————————————————— Γ ⊢ x ≈ y Γ ⊢ (x :: τ) ≈ (y :: τ') If one of the patterns has a bang pattern, the other one needs one as well. Γ ⊢ τ ≈ τ' ————————————— ———————————————————————————— Γ ⊢ !x ≈ !y Γ ⊢ !(x :: τ) ≈ !(y :: τ') |
Defined in FreeC.IR.Similar | |
Similar Alt Source # | Two alternatives that match the same constructor Γ ∪ { x₁ ↦ y₁, …, xₙ ↦ yₙ } ⊢ e ≈ f, Γ ⊢ p₁ ≈ q₁, …, Γ ⊢ pₙ ≈ qₙ —————————————————————————————————————————————————————————————————— Γ ⊢ C p₁ … pₙ -> e ≈ C q₁ … qₙ -> f where |
Defined in FreeC.IR.Similar | |
Similar Expr Source # | The similarity relation of expressions is governed by the the following inference rules
|
Defined in FreeC.IR.Similar | |
Similar FuncDecl Source # | Two function declarations are similar if their right-hand sides are
similar under an extended Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ, x₁ ↦ y₁, …, xₙ ↦ yₙ } ⊢ e ≈ f Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ } ⊢ p₁ ≈ q₁, …, Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ } ⊢ pₙ ≈ qₙ —————————————————————————————————————————————————————————— Γ ⊢ g @α₁ … @αₘ p₁ … pₙ = e ≈ g @β₁ … @βₘ q₁ … qₙ = f where If the function has an explicit return type annotation, the annotated return typed must be similar as well. Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ, x₁ ↦ y₁, …, xₙ ↦ yₙ } ⊢ e ≈ f Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ } ⊢ p₁ ≈ q₁, …, Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ } ⊢ pₙ ≈ qₙ, Γ ∪ { α₁ ↦ β₁, …, αₘ ↦ βₘ } ⊢ τ ≈ τ', —————————————————————————————————————————————————————————— Γ ⊢ g @α₁ … @αₘ p₁ … pₙ :: τ = e ≈ g @β₁ … @βₘ q₁ … qₙ :: τ' = f |
Defined in FreeC.IR.Similar | |
Similar TypeSig Source # | Two type signatures are similar if they annotate the type of the same functions with similar types. Γ ⊢ τ ≈ τ' ———————————————————————————————————————— Γ ⊢ f₁, … , fₙ :: τ ≈ f₁, … , fₙ :: τ' |
Defined in FreeC.IR.Similar | |
Similar TopLevelDecl Source # | Only top-level declarations of the same type can be similar. |
Defined in FreeC.IR.Similar similar' :: TopLevelDecl -> TopLevelDecl -> Renaming -> Bool | |
Similar ImportDecl Source # | Two import declarations are similar if they import the same module. |
Defined in FreeC.IR.Similar similar' :: ImportDecl -> ImportDecl -> Renaming -> Bool | |
Similar node => Similar [node] Source # | Two lists of nodes are similar if the corresponding elements are similar and each element has a corresponding element (i.e., the lists are of the same length). Γ ⊢ x₁ ≈ y₁, …, Γ ⊢ xₙ ≈ yₙ ——————————————————————————————— Γ ⊢ [x₁, …, xₙ] ≈ [y₁, …, yₙ] |
Defined in FreeC.IR.Similar | |
Similar node => Similar (Maybe node) Source # | Two optional nodes are similar when they are either both not present or both are present and similar. Γ ⊢ x ≈ y ——————————————————————— ————————————————————— Γ ⊢ Nothing ≈ Nothing Γ ⊢ Just x ≈ Just y |
Defined in FreeC.IR.Similar | |
Similar contents => Similar (ModuleOf contents) Source # | Two modules are similar if their names and contents are similar. |
Defined in FreeC.IR.Similar |