gpt4 book ai didi

python - 如何使这些动态类型的函数类型安全?

转载 作者:太空狗 更新时间:2023-10-29 20:26:52 26 4
gpt4 key购买 nike

<分区>

是否有任何编程语言(或类型系统)可以以静态类型和类型安全的方式(无需使用强制转换、运行时检查等)表达以下 Python 函数?

#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()

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com