tailieunhanh - compilers principles techniques and tools phần 5

Kiểm tra các định nghĩa chức năng và biểu thức trong chuỗi đầu vào. Sử dụng kiểu suy luận của một hàm nếu nó sau đó được sử dụng trong một biểu thức. Đối với E = chức năng định nghĩa thú vị IDL (id2), tạo ra các biến loại tươi và, 8. Liên kết các loại - 8 +, với IDL chức năng, và loại với các id2 tham số. Sau đó, suy ra một biểu thức E. | Simpo PDF Merge and Split Unregistered Version - http Check the function definitions and the expression in the input sequence. Use the inferred type of a function if it is subsequently used in an expression. For a function definition fun idi id2 E create fresh type variables a and 3. Associate the type a -4 f3 with the function idi and the type a with the parameter id2. Then infer a type for expression E. Suppose a denotes type s and 3 denotes type t after type inference for E. The inferred type of function idi is s - t. Bind any type variables that remain unconstrained in s - t by V quantifiers. For a function application E1 E2 infer types for El and E2. Since El is used as a function its type must have the form s s . Technically the type of El must unify with 3 7 where 3 and 7 are new type variables . Let t be the inferred type of El. Unify s and t. If unification fails the expression has a type error. Otherwise the inferred type of E1 E2 is s . For each occurrence of a polymorphic function replace the bound variables in its type by distinct fresh variables and remove the V quantifiers. The resulting type expression is the inferred type of this occurrence. For a name that is encountered for the first time introduce a fresh variable for its type. Example In Fig. we infer a type for function length. The root of the syntax tree in Fig. is for a function definition so we introduce variables 3 and 7 associate the type 3-4-7 with function length and the type 3 with x see lines 1-2 of Fig. . At the right child of the root we view if as a polymorphic function that is applied to a triple consisting of a boolean and two expressions that represent the then and else parts. Its type is v a. boolean X a X a -4- a. Each application of a polymorphic function can be to a different type so we make up a fresh variable Oti where i is from if and remove the V see line 3 of Fig. . The type of the left child of if must unify with boolean and the

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.