## Concept:

# Metaprogram

## Headline

A program that manipulates programs

## Illustration

Consider the following simplify for arithmetic expressions, written in Language:Haskell:

```
-- Simple arithmetic expressions
data Expr = Const Int | Add Expr Expr
deriving (Eq, Show)
-- Simplification for unit law of addition
simplify :: Expr -> Expr
simplify t@(Const c) = t
simplify (Add (Const 0) x) = simplify x
simplify (Add x (Const 0)) = simplify x
simplify t@(Add x y) =
if t==t'
then t
else simplify t'
where
t' = Add (simplify x) (simplify y)
```

For instance, the simplifier works as follows:

```
> simplify (Add (Const 20) (Const 22))
Add (Const 20) (Const 22)
> simplify (Add (Const 0) (Const 42))
Const 42
```

The simplifier is a metaprogram, as it is a program that manipulates another program. The metalanguage used here is Language:Haskell. The object language used here is *Expr*, the language of expression.

See the concept of reflection for a more specific form of metaprogramming for further illustrations.

## Metadata

### There are no revisions for this page.

## User contributions

## 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:

- Concept:Semantic equality - 0.9689457
- Technology:QuickCheck - 0.74164575
- Concept:Structural equality - 0.6075911
- Concept:Fold algebra - 0.5305707
- Concept:Function composition - 0.43458125
- Concept:Module - 0.41122124
- Concept:Total order - 0.40661797
- Concept:Currying - 0.37894562
- Concept:Type-class constraint - 0.3786829
- Concept:Maybe monad - 0.3725355

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