## 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.9678692
- Technology:QuickCheck - 0.7410642
- Concept:Structural equality - 0.6069193
- Concept:Fold algebra - 0.5331551
- Concept:Function composition - 0.43868017
- Concept:Module - 0.41525406
- Concept:Total order - 0.40959308
- Concept:Type-class constraint - 0.38547236
- Concept:Currying - 0.3785787
- Concept:Maybe monad - 0.37474087

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