Lecture 2 Notes

4 2 2 2 2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t;( '4 ¢ 1¡ ¢© © 2  36 ¡ £ ©¤ ©¤ '#4 "1¡ ©    (  © ¢ 2   2     $  ¡ # ¢ (4¡   # %)¢ % ¡  % ¡  ¨( ¡ 2 ¨  3¡ # ¢ #%¡ '% ¢ ( ¡ ©¤ ¢  © ( 1¡ 4 %)¢ %(  (© ¡ %  # ¡   ¨  ¤¦¢ ¥$£¡  '#! $¨ '#! $¨      ©  2  extend-subst usage: 2  tv1  The constructors for substitutions are and . produces a representation of the empty substitution. tv t takes the substitution and adds the equation tv t to it, as we did in the preceding section. We write [tv t ] for the resulting substitution. This was a two-step operation: first we substituted t for tv in each of the right-hand sides of the equations in the substitution, and then we added the equation tv t to the list. Pictorially, ¢© © 2 ¨  ¡   ( 4 ¡ 2  ¤¦¢ ¥$£¡ # % ¡ This implementation does not depend on, nor does it attempt to enforce, the nooccurrence invariant. That is the job of the unifier, in the next section. 37 6.5.2 The Unifier '¤  ¥¦ ¤ The main procedure of the unifier is . The unifier performs one step of the inference procedure outlined above: It takes two types, and ,a substitution that satisfies the no-occurrence invariant, and an expression . It returns the substitution that results from adding to . This substitution will also satisfy the no-occurrence invariant. If adding yields an inconsistency, then it reports an error, and blames the expression . This is typically the expression that gave rise to the equation . ¢ §¡ ¢£¢  $ ¢¢ ¡ § ££ $ £¢ ¡¢ ¡  $ £¢ ¡ ¢ © © § £¢  $ £¢ ¡ ¡ $ £¢ ¡ §¡ ¢£   ¢© © 2  2 ¨   ¢ §¡ ¢£   Think of the substitution as a store, and an unknown type is a reference into that store. produces the new store that is obtained by adding to the store. '  ¥§¤ ¤¦ ©© #  "4  ¨ This is an algorithm for which gives awkward code, so we use simple predicates and extractors on types instead. 38  §¡ ¢£¢ $ £¢ ¤ ¡ ¡¢ © £ ¨ ©  ¢© © ¢© © §¡ ¢£¢ ¡ £¢ ¢ © ¥ £ ¤ ¡¢ $ £¢ £¢ ¢ © ¥ £ ¡ ¡ ¤ ¡¢ ¢© © ¢ ¢© © §¡¢ ¢£§ £¢ ¥ £ £¢ ¡¦¤ ¡ $ £§ £¢ ¥ £ £¢ ¡¢ ¡¦¤ ¡ ¢© ©  ¢ § £¢ ¡ ¡¢ ¢ $ £¢ £ ¡ ¡¢ $ ¢£¢¢¢ ¤ ¨ ¤ ¡¢ §¡ © ¥ $ ££§ £¡¢ © © ¢ © © ¨ ¡¢ ¡¢ ¢ $ £¢ ¢£ ¡ §¡¢ §¡¢ ¢£ £¢ ¡ ¢ §¡ ¢¢¢ $ ¢¢ ¤ ¨ ¤ ¡ © ¥ § £¢ $ £¡¢ © © ¢ © © ¡ ¡¢ ¢ ¨ §¡ ¢£¢ $ £ ¡¢ $ £ £¢ ¢ ¡¢ ¡ ¢ © © ¢£¢ $ £¢ £ §¡ ¡ ¢ ¢ © §¢¢§ £ ¢ ¢ © © ¡ © §¡¢ ¡¢ §¡ ¢£¢ ¢ © £$ ¢§ £ ¢ ¢ © © ¡ © ¡¢ ¡¢ $ £¢  ¡ ¢ ¢ © © ¢£¢ $ £¢ §¡ ¡  ¨     © $%  )  © $%  )  39  ' )¨) (''© % " $ ¡ ©4(' ") ¡ ©4(' ") ¡ '¤¦ "¥§¤   © '# ©   )  ) 0 )   2   ¨ ©   " ¤ # '  )£¡  2 2     ' ©     ' ©      ¨  ©   )                2  ¡ 2  ¡ ¨¡  % ¡ ©4(' "¨)3¡ '# ) "¨)3¡ © ©4('   2 ¨ '¤ ¡ ¡ ¡  % ¡   ¥¦ ¤  ©4 ' "¨()$ ¡ 0   ") ¡ ©4(' ¢ # ¡ ¡   4 $) 4)&...
View Full Document

This document was uploaded on 03/17/2014 for the course CSG 111 at Northeastern.

Ask a homework question - tutors are online