Пожалуйста, уточните, какие входные данные получают ваши функции и какие выходные они должны генерировать.Это очень важно!Поскольку вы не были конкретны, любой, кто пытается помочь вам, должен будет угадать, что вы хотите сделать.
Из вашего заявления:
In order for a conditional expression to be type correct:
a) All predicates must be boolean
b) All consequents must have the same type
If it typechecks:
The type of the conditional expression
is the type of the consequent expressions.
Это означает, что почти напрямую () код:
def typeConditional(condition, env):
#receives a conditional expression, and an execution environment
# returns the expression's type if it is well typed
# or None otherwise
predicates = get_predicate_expressions(condition)
if any predicate has a type that is not Bool:
return None
else:
consequents = consequent_expressions(consition)
the_type = typcheck(first consequent, env)
if all consequents have type the_type:
return the_type
else:
return None