Headline

Equality in terms of structure alone, without interpretation

Illustration

Structural equality means that two expressions are equal if and only if they agree on constructors or primitive values at every level and in every position. In Haskell, this would be captured by the following type-class instance for the type class Eq:

-- Simple arithmetic expressions
data Expr = Const Int | Add Expr Expr

-- Uniform (structural) equality
instance Eq Expr
  where
    (Const i) == (Const j) = i == j
    (Add e1 e2) == (Add e3 e4) = e1 == e3 && e2 == e4
    _ == _ = False

Thus, the operands of equality (i.e., "==") must agree on the outermost constructor and equality must hold recursively for all immediate positions. For instance:

> Const 42 == Const 42
True
> Const 42 == Add (Const 20) (Const 22)
False

The second equality test fails because the constant term is clearly structurally unequal to the addition term, even though we can see that both expressions would evaluate to the same result. Indeed, sometimes, we could prefer semantic equality; this is when we take semantic properties of the underlying data into account.

Metadata


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    10 most similar pages:

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.