小编Kyu*_*chi的帖子

where 子句中的类型推断

如果我写

foo :: [Int]
foo = iterate (\x -> _) 0
Run Code Online (Sandbox Code Playgroud)

GHC 高兴地告诉我那x是一个Int,那个洞应该是另一个Int。但是,如果我将其重写为

foo' :: [Int]
foo' = iterate next 0
  where next x = _
Run Code Online (Sandbox Code Playgroud)

它不知道 的类型x,也不知道洞是什么。如果我使用let.

where除了手动添加类型签名之外,还有什么方法可以恢复绑定中的类型推断?

haskell type-inference ghc

7
推荐指数
1
解决办法
65
查看次数

从另一个函数复制类型签名

想象一下,我有一组如下所示的功能。foo有很多不同类型的参数,bar并将所有参数传递给另一个函数。有什么方法可以让 mypy 理解barfoo不显式复制整个参数列表的类型相同?

def foo(a: int, b: float, c: str, d: bool, *e: str, f: str = "a", g: str = "b") -> str:
    ...

def bar(*args, **kwargs):
    val = foo(*args, **kwargs)
    ...
    return val
Run Code Online (Sandbox Code Playgroud)

python mypy python-typing

4
推荐指数
1
解决办法
371
查看次数

标签 统计

ghc ×1

haskell ×1

mypy ×1

python ×1

python-typing ×1

type-inference ×1