• Keine Ergebnisse gefunden

Definition of simple data structures

N/A
N/A
Protected

Academic year: 2021

Aktie "Definition of simple data structures"

Copied!
7
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

12

(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

13

(3)

Parametric polymorphism

id :: a -> a id x = x

len :: [a] -> Int len [] = 0

len (x:xs) = len xs + 1

(++) :: [a] -> [a] -> [a]

[] ++ ys = ys

(4)

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

(5)

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

(6)

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)

(7)

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)

Referenzen

ÄHNLICHE DOKUMENTE

Assume that the result of the function application is totally required...

multipoint and range query: index on hundreds B + -tree and hash indexes are clustered. bitmap index is

Inefficient: clustered composite index on (longitude, latitude) each longitude 5 to 15 has some pointers to latitude 22 records General geographical queries should use

• Stock size may increase seven-fold if fish are caught after multiple spawning, at around 2/3 of their maximum length.. • Large stock size means low cost

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

- 1988: Waterloo Maple Software was founded in order to sell and improve the software - currently: version 12.

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

• Mapping, (or 8lngle level atorase) where the system sets up an association between a local or remote object and a process's virtual address space 80 that the