Interpretador tipos chequeo I
Debemos incluir las expresiones de tipo:
- proc
- letrec
proc(int x) ...
proc((int*int -> int) x)
proc((int -> (int*int -> int)) x)
letrec
int f(int x, int y) = ....
(int*int -> int) g(int x) = ....
Modificaciones en la gramática¶
(expression ("proc" "(" (separated-list type-exp identifier ",") ")" expression) proc-exp)
(expression ("letrec" (arbno
type-exp identifier "(" (separated-list type-exp identifier ",") ")"
"=" expression)
"in"
expression) letrec-exp)
(type-exp ("int") int-exp)
(type-exp ("bool") bool-exp)
(type-exp
("(" (separated-list type-exp "*") "->" type-exp ")") proc-type-exp)
Representación de tipos¶
Se definen dos tipos principales:
- Tipo atómico: Tipo primitivo, no compuesto por otros tipos
- Tipo procedimiento: Especifica tipos de argumentos y tipo del resultado
; Tipos
(define-datatype type type?
(atomic-type
(nombre symbol?))
(proc-type
(arg-type (list-of type?))
(result-t type?)))
; int
(define int-type (atomic-type 'int))
; bool
(define bool-type (atomic-type 'bool))