• Keine Ergebnisse gefunden

Definition of natural numbers

N/A
N/A
Protected

Academic year: 2021

Aktie "Definition of natural numbers"

Copied!
6
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

haskell -patterns

pat var

|

| integer

| float

| char

| string

| (constr pat

1 . . . pat

n)

| [pat

1, . . . , pat

n], n 0

| (pat

1, . . . , pat

n), n 0

1

(2)

haskell -types

type (tyconstr type

1 . . . type

n), n 0

| [type]

| (type

1 type

2)

| (type

1, . . . , type

n), n 0

| var

tyconstr string starting with upper case symbol

2

(3)

Top declarations and type introduction

topdecl decl

| type tyconstr var1 . . . varn = type, n 0

| data tyconstr var1 . . . varn = constr1 type

1,1 . . . type

1,n1 | ...

constrk type

k,1 . . . type

k,nk,

n 0, k 1, ni 0

3

(4)

Definition of simple data structures

data Color = Red | Yellow | Green data MyBool = MyTrue | MyFalse

traffic_light :: Color -> Color traffic_light Red = Green

traffic_light Green = Yellow traffic_light Yellow = Red

und :: MyBool -> MyBool -> MyBool und MyTrue y = y

und _ _ = MyFalse

4

(5)

Definition of natural numbers

data Nats = Zero | Succ Nats

plus :: Nats -> Nats -> Nats plus Zero y = y

plus (Succ x) y = Succ (plus x y) half :: Nats -> Nats

half Zero = Zero

half (Succ Zero) = Zero

half (Succ (Succ x)) = Succ (half x)

5

(6)

Definition of lists

data List a = Nil | Cons a (List a)

len :: List a -> Nats

len Nil = Zero

len (Cons x xs) = Succ (len xs)

append :: List a -> List a -> List a append Nil ys = ys

append (Cons x xs) ys = Cons x (append xs ys)

6

Referenzen

ÄHNLICHE DOKUMENTE

In the second part some effective representations of the open subsets of the real numbers are introduced and

ƒ Abgeleitete Datentypen (engl. derived types) sind auf der Basis von anderen Datentypen definiert (z.B. primitive types) sind hingegen nicht von anderen Datentypen abgleitet..

The object was to provide for the other two square roots of unity which are always ignored in the complex field and then to be able to take square roots of all numbers in terms of

 The economic consequences of an exposed object (an impact model linking water depth, duration of inundation, flow velocity with economic losses). Environmental Risk: Unit

Take a Latin square of order n and superimpose upon it a second square with treatments denoted by greek letters. The two squares are orthogonal if each Latin letter occurs with

A natural number different from 1 that is divisible by 1 and itself only is called a prime number [Primzahl].. Examples of primes are: 2, 3, 5, 7, 2003, 2 13

Karlsruher Institut f¨ ur Technologie Institut f¨ ur Theorie der Kondensierten Materie Ubungen zur Klassischen Theoretischen Physik I ¨ WS

Before presenting a possible application of the cognitive idea to a real-time capable SONAR system the definition and general idea of such a cognitive system is given.. As stated in