• Keine Ergebnisse gefunden

A 0 (x) = ∀a. a for all x ∈ V

N/A
N/A
Protected

Academic year: 2021

Aktie "A 0 (x) = ∀a. a for all x ∈ V"

Copied!
4
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Initial Type Assumption A 0

A 0 (x) = ∀a. a for all x ∈ V

A 0 (c) = pre-defined type schema in haskell , for all c ∈ C 0 A 0 (constr) = ∀ (type

1 → . . . → type

n → (tyconstr a 1 . . . a m )), A 0 (bot) = ∀a. a

A 0 (if) = ∀a. Bool → a → a → a A 0 (fix) = ∀a. (a → a) → a

A 0 (isa constr ) = ∀ (( tyconstr a 1 . . . a m ) -> Bool) A 0 (argof constr ) = ∀ ((tyconstr a 1 . . . a m ) -> (type

1 , . . . , type

n )) A 0 (isa n−tuple ) = ∀a 1 . . . a n . (a 1 , . . . , a n ) → Bool

A 0 (sel n,i ) = ∀a 1 . . . a n . (a 1 , . . . , a n ) → a i

A 0 (tuple n ) = ∀a 1 . . . a n . a 1 → . . . → a n → (a 1 , . . . , a n )

Here, constr is introduced by the declaration

data tyconstr a 1 . . . a m = . . . |constr type

1 . . . type

n | . . .

59

(2)

Type Inference Algorithm W

Let A be a type assumption, let t ∈ Λ.

W (A, t) is either a pair (θ, τ ) or the computation fails because of a failing unification problem. Let c ∈ C ∪ V .

• W ( A + {c :: ∀a 1 , . . . , a n . τ }, c ) = ( id, τ [a 1 /b 1 , . . . , a n /b n ] ), b 1 , . . . , b n are new variables

• W ( A, λx. t ) = ( θ, bθ → τ ),

where W ( A + {x :: b}, t ) = (θ, τ ), b is a new variable

• W ( A, (t 1 t 2 ) ) = ( θ 1 θ 2 θ 3 , bθ 3 ),

where W ( A, t 1 ) = ( θ 1 , τ 1 ) W ( A θ 1 , t 2 ) = ( θ 2 , τ 2 )

θ 3 = mgu(τ 1 θ 2 , τ 2 → b), b is a new variable.

60

(3)

Example

W(A0,fix(λfactx. if (x <=0) 1 (fact(x − 1)∗ x))) = ([. . .],Int → Int) W(A0,fix) = (id,(a1 → a1) → a1)

W(A0, λfactx. if (x <=0) 1 (fact(x− 1)∗x)) = ([. . .],(Int → Int) → (Int → Int)) W(A0 + {fact :: b1}, λ x. if (x <=0) 1 (fact(x− 1)∗x)) = ([b1/Int → Int, . . .],Int → Int) W(A0 + {fact :: b1, x :: b2},if (x <=0) 1 (fact(x− 1)∗x)) = ([b2/Int, b1/Int → Int, . . .],Int)

W(A0 + {fact :: b1, x :: b2},if (x <=0) 1) = ([b2/Int, . . .],Int → Int) W(A0 +{fact :: b1, x :: b2},if (x <=0)) = ([b2/Int, . . .], a2 → a2 → a2)

W(A0 +{fact :: b1, x :: b2},if) = (id,Bool → a2 → a2 → a2) W(A0 + {fact :: b1, x :: b2},(x <=0)) = ([b2/Int, . . .],Bool)

W(A0 + {fact :: b1, x :: b2},(x <=)) = ([b2/Int, . . .],Int → Bool) W(A0 +{fact :: b1, x :: b2},<=) = (id,Int → Int → Bool)

W(A0 + {fact :: b1, x :: b2}, x) = (id, b2)

mgu(Int → Int → Bool, b2 → b3) = [b2/Int, b3/Int → Bool]

W(A0 + {fact :: b1, x :: Int},0) = (id,Int) mgu(Int → Bool,Int → b4) = [b4/Bool]

mgu(Bool → a2 → a2 → a2,Bool → b5) = [b5/a2 → a2 → a2] W(A0 + {fact :: b1, x :: Int},1) = (id,Int)

mgu(a2 → a2 → a2,Int → b6) = [b6/Int → Int]

W(A0 +{fact :: b1, x :: Int},fact(x − 1) ∗x) = ([b1/Int → Int, . . .],Int)

W(A0 + {fact :: b1, x :: Int},fact(x− 1)∗) = ([b1/Int → Int, . . .],Int → Int) W(A0 + {fact :: b1, x :: Int},∗)) = (id,Int → Int → Int)

W(A0 +{fact :: b1, x :: Int},fact(x − 1)) = ([b1/Int → b9, . . .], b9)

61

(4)

W (A

0

+ {fact :: b

1

, x :: Int}, fact) = (id, b

1

) W (A

0

+ {fact :: b

1

, x :: Int}, x − 1) = ([. . .], Int)

W (A

0

+ {fact :: b

1

, x :: Int}, x−) = ([. . .], Int → Int)

W (A

0

+ {fact :: b

1

, x :: Int}, −) = (id, Int → Int → Int) W (A

0

+ {fact :: b

1

, x :: Int}, x) = (id, Int)

mgu(Int → Int → Int, Int → b

7

) = [b

7

/Int → Int]

W (A

0

+ {fact :: b

1

, x :: Int}, 1) = (id, Int) mgu(Int → Int, Int → b

8

) = [b

8

/Int]

mgu(b

1

, Int → b

9

) = [b

1

/Int → b

9

]

mgu(Int → Int → Int, b

9

→ b

10

) = [b

9

/Int, b

10

/Int → Int]

W (A

0

+ {fact :: Int → Int, x :: Int}, x) = (id, Int) mgu(Int → Int, Int → b

11

) = [b

11

/Int]

mgu(Int → Int, Int → b

12

) = [b

12

/Int]

mgu((a

1

→ a

1

) → a

1

, ((Int → Int) → (Int → Int)) → b

13

) = [a

1

/Int → Int, b

13

/Int → Int]

62

Referenzen

ÄHNLICHE DOKUMENTE

Wenn der Graph einer Funktion f an der Stelle 1 einen Hochpunkt und an der Stelle 3 einen Tiefpunkt hat, dann liegt zwischen den Stellen 1 und 3 ein Wendepunkt des Graphen.. 4.1

Sind die Summanden in einer Reihe selbst Funktionen einer Variablen x, so stellt der Ausdruck P ∞. n=0 a n (x) eine Funktion dar,

Z: Stetige Zufallsvariablen... Z: Stetige ZV

1) Die Normalform und die Punktrichtungsform sind die zwei meist benützten Formen der Koordinatengleichung. 2) Aus einer Parametergleichung kann durch Elimination des Parameters die

Betrachten wir die folgende rote Funktion bezüglich der schwarzen durch den Ursprung des Koordinatensystems O(0;0) verlaufenden Funktion. Abstand der Punkte mit

Zeigen Sie nun mit Hilfe des Satzes von Baire die Behauptung. Abgabetermin:

Rate eine Nullstelle x 1 als Faktor des

(Dauer 90 Minuten, alle Unterlagen sind erlaubt, bitte alle Zwishenshritte angeben). Anmeldung zur mündlihen Prüfung im Sekretariat,