Como fazer com que essas funções digitadas dinamicamente sejam seguras para o tipo? [fechadas]
Existe alguma linguagem de programação (ou sistema de tipos) na qual você possa expressar as seguintes funções Python de maneira estaticamente tipificada e segura para o tipo (sem ter que usar conversões, verificações de tempo de execução, etc.)?
#1
:
# My function - What would its type be?
def Apply(x):
return x(x)
# Example usage
print Apply(lambda _: 42)
#2
:
white = None
black = None
def White():
for x in xrange(1, 10):
print ("White move #%s" % x)
yield black
def Black():
for x in xrange(1, 10):
print ("Black move #%s" % x)
yield white
white = White()
black = Black()
# What would the type of the iterator objects be?
for it in white:
it = it.next()