[an error occurred while processing this directive]
(define ints-from (lambda (n) (cons n (ints-from (+ n 1)))))
(define fibo-gen (lambda (a b) (cons a (fibo-gen ____ __________)))) (define fibos (fibo-gen 0 1)) (define get-nth (lambda (lst n) (if (= n 0) (car lst) (get-nth (cdr lst) (- n 1))))) (define fibo (lambda (n) (get-nth _______ n)))
(define merge-lists (lambda (lst1 lst2 proc) (if (null? lst1) null (if (null? lst2) null (cons (proc (car lst1) (car lst2)) (merge-lists (cdr lst1) (cdr lst2) proc)))))) (define fibos (cons 0 (cons 1 (merge-lists ___________ ______________ +))))
What is the difference between manifest and latent types?
What is the difference between static and dynamic type checking?
What does increasing the strictness of a language's type checking do?
What are the advantages and disadvantages of static type checking?
CPrimitiveType ::= Number | Boolean
CProcedureType ::= ( CProductType -> Type)
CProductType ::= ( CTypeList )
CTypeList ::= CType CTypeList
CTypeList ::=
What is the type of:
(lambda (f:((Number) -> Number) g:((Number) -> Number)) (lambda (x:Number) (f (g x)))))
class CPrimitiveType(CType): def __init__(self, s): self._name = s def __str__(self): return self._name def isPrimitiveType(self): return True def matches(self, other): return other.isPrimitiveType() \ and ________________________
class CProcedureType(CType): def __init__(self, args, rettype): self._args = args self._rettype = rettype def __str__(self): return "(" + str(self._args) + " -> " \ + str(self._rettype) + ")" def isProcedureType(self): return True def getReturnType(self): return self._rettype def getParameters(self): return self._args def matches(self, other): return ________________________________ and ___________________________________________ and ___________________________________________
def typecheck(expr, env): if isPrimitive(expr): return typePrimitive(expr) elif isConditional(expr): return typeConditional(expr, env) elif isLambda(expr): return typeLambda(expr, env) elif isDefinition(expr): typeDefinition(expr, env) elif isName(expr): return typeName(expr, env) elif isApplication(expr): return typeApplication(expr, env) else: evalError ("Unknown expression: " + str(expr))
class Environment: # Store a [type, value] pair for each variable. ... def addVariable(self, name, typ, value): self._frame[name] = (typ, value) def lookupPlace(self, name): if self._frame.has_key(name): return self._frame[name] elif (self._parent): return self._parent.lookupPlace(name) else: return None def lookupVariableType(self, name): place = _____________________ if place: return ______________ else: return CErrorType("Name not found") def lookupVariable(self, name): return self.lookupPlace(name)[1] ...
def typeDefinition(expr, env): assert isDefinition(expr) if len(expr) != 5: evalError ("Bad definition: %s" % str(expr)) name = expr[1] if isinstance(name, str): if expr[2] != ':': evalError ("Definition missing type: %s" % str(expr)) typ = CType.fromParsed(expr[3]) etyp = __________________________ if not typ.matches(etyp): evalError("Mistyped definition: ..." % (name, typ, etyp)) elif isinstance(name, list): evalError ("Procedure definition syntax not implemented") else: evalError ("Bad definition: %s" % str(expr))
def typeLambda(expr, env): # error checking code removed newenv = Environment(env) params = expr[1] paramnames = [] paramtypes = [] for i in range(0, len(params) / 3): name = params[i*3] typ = CType.fromParsed(params[(i*3)+2]) paramnames.append(name) paramtypes.append(typ) newenv._________________________________ resulttype = ___________(expr[2], newenv) return CProcedureType(CProductType(paramtypes), resulttype)[an error occurred while processing this directive]