and is and the other is or one is otherwise

Info icon This 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: ¢¡ ¢ © £ ¢ ¡¢ $ ¡¢¢ ¢ £¢ ¢ © ¢ © © ¡ ¡ $ £¢ ¢ £ £ ¢ © © ¡ ¡ ¡¢ ¦ ¡¢ ¢ ¡ £¢ ¢ © ¡¦ £¢ ¥ ¡¢ £  ¢¢ £¢ © © ¡ ¡ $ ¢ ¢  £¢ ¡¢ ¡ ¢© © ¡ $ £¢  ¢  £¢ ¨¢ ¤©  © ¡ ¡ ¢£ ¢ ¡ £ $ £¡¦ ¢ ¢ ¢ © © ¡¢ ¢ ¡ ¢¡  $ ¢¢ £ £¢ ¢ © © ¡ ¢ ¥ £¢ ¢ ¢ ¡ £¢ ¤ ¡ ¡ ¤  ¨  ¨    '#! )  ) '#! $¨   ) © $%     '#! $¨ 2   ' 2  ©'  # ¤ ¢   ¢ ¤# )) 2 (  ¡ )£ ¤ '#! $  )   '  ) 0%   ¨# ©   ¡  "4    ' ¡ )£ $' ' © '#! $   44 ( %   ¡ ¦ 1¡ ¤ © #! ' $ ¡ ©4(' "¨)$ ¡    ©  '! $" ' )¦ (  $ '#! $ ©4(' ") ¡ " #4 ¡ 2  ¡ # ¢ (© %  ¥¨ # ¤' ¥¨ 2  '#! )  ) ¡   (©  %  # ¡  (©  %  # ¡  ©'  # ¡ ' $ #!  ¡ ¦( '  ©   )  © $%    2 ¨ © ¥ ©¥ ¤  ¡  £¢ ¡ ¢ ¢ ¥£© ¤¢ 2 34 This procedure deals with substituting for a single type variable. It doesn’t deal with full-fledged substitutions like those we had in the preceding section.  ©       ¤    ¤ # % ¡ ¤¦¢ ¥$£¡  ¤  ( 2  apply-one-subst usage: (©  %  # ¡  We call these extended types type expressions. A basic operation on type expressions is substitution of a type for a type variable, defined by  '  © 2 ¨ ¨ ¢ ¢ ¡ ©'#! )¢ $¨ ©% # ¤ " ¡ ' ¢ ¢ ¡ ©'#! )£ $ Type :: Number We represent unknown types (sometimes called type variables) as an additional variant of the datatype. We do this using the same technique that we to add lexical addresses to our SLLGEN grammars. We add to the grammar the additional production ¢ ¡ )£ We will build the implementation in a bottom-up fashion. We first consider substitutions. 6.5.1 Substitutions A substitution is a list of equations between type variables and types. Equivalently, we can think of this list as a function from type variables to types. We say a type variable is bound in the substitution if and only if it occurs on the left-hand side of one of the equations in the substitution. We represent a substitution as a list of (type variable, type) pairs. The basic observer for substitutions is . This walks through the type, replacing each type variable by its binding in the substitution. If a variable is not bound in the substitution, then it is left unchanged. The implementation uses the Scheme procedure to look up the type variable in the substitution. returns either the matching (type variable, type) pair or if the given type variable is not the car of any pair in the list.  ) © © © ( © $ 2  © % ¡ ¥¨ # # © ¨© 4 ( ¦ # ¡ ¢¢ ¢  ¢  ¢ © © £¢ © ¢  ¡ © ¢ © £ ¢ ¡¢ ¢ © §§ § £  ¢ © © ¡ © ¢ ¡¢ ¢ ¢ © £$ § £  ¢ © © ¡ © ¢ ¡¢ ¢ ¡¢ ¢ §¢ $¢ ¡¢ £ ¡ £¢ ¡¢ £ ¡¢ £ ¢ ¡¢ £ ¢ ¡ ¢¢ ¡ £¢ © © ¢ © © £¢ ¡ ¡¢ £ ¢ ¢ © © ¡ ¢ £ ¢ © ¡ £¢ © ¡  ) ¡¤ £ £©  ) 2   ) © ( © $ © %  ¥¨ # 2  ¡ 2     ©( © ¥ $   2    ©( © ¥ $   2   2  ©  %  # ¡  2 ¨ 2 ¨ # ¡  4 ¨( ©  %  # ¡  ¡         © #! ' $ ¡ ¡ ¡ '4 ¢ 1¡   ¨ %¡ ¦¤ §1¡   ¤¦¢ ¥$£¡ # " 4 ¡ 2  # ¢ # % ¡    ) "¨)$ ¡ ©4('    ") ¡  ©4(' ¨ ¡ 2 2  ©%( ¡    ¨( ¡  ©%(  )   (  ¡    $ 1¡  © ¤ ¡  ) ) 1¡ © ¤ 35 4 ¨( ¢  ¢ ¢© © ¡ £ apply-subst-to-type ¢ © © £ ¡¢ ©     ¡ ¡¢ © © ¢© © 2  © ¢ 2  © ¢ ¢ ¥ ¢ ¨ ¢ © © £ ¡¢  $   ©  2   )  ¡     tn [tv t t] ¨ ¤ tvn tv t] ¦ £ t] ¢££ §¦¦¥ ¦ [tv tn t1 [tv . . . ¨ ¢££ £ tvn tv1 §¦¦¥ t1 . . . ¤ This definition has the property that for any type t, (t )[tv t] t ]) © © t( [tv ¢© © © ¢ ¢ ¥  $  follows the picture above. It substitutes t 0 The implementation of for tv0 in all of the existing bindings in 0 , and then adds the binding for t0 . 2   ¡¢ £ ¢ © © ¡ £¢ ¡¢ © © ¢ ¢© © ¨ ¢ ¡ ¢© © ¡ ¥ ¢ ¢ ¢ © © ¤¥ £¢ ¢ ¢ © © ¡ ¢ © © £ ¡¢   ¡ ¦  # $¢  ) © 2  2  ¡  2 ¨ # % ¡ ' $ #! ¤ ¢   ( ¢ ' # # % 2  2 '#! $     ¢  ¢ ©¤ '#! $ '¢% &quo...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern