这是以下类型>>=:
(>>=) :: Monad m => m a -> (a -> m b) -> m b
Run Code Online (Sandbox Code Playgroud)
它需要一个函数作为第二个参数.
这是以下类型return:
return :: Monad m => a -> m a
Run Code Online (Sandbox Code Playgroud)
返回 m a
这显然是类型检查:
(>>) :: Monad m => m a -> m b -> m b
x >> y = x >>= (\_ -> y)
Run Code Online (Sandbox Code Playgroud)
但为什么以下类型检查和工作类似于上面的代码?
(>>) :: Monad m => m a -> m b -> m b
x >> y = x >>= return y
Run Code Online (Sandbox Code Playgroud)
这 …
有没有办法正确键入流程或打字稿中的以下代码?:
type A = {
x: string
}
type B = {
y: string
}
function get(obj, prop) {
return obj[prop];
}
const a: A = { x: 'x' }
const b: B = { y: 'y' }
get(a, 'x') // should type check
get(b, 'y') // should type check
get(a, 'y') // should NOT type check
get(b, 'x') // should NOT type check
Run Code Online (Sandbox Code Playgroud)
任何类型的get通用功能在哪里obj.我们可以用流检查是否obj有的方式来注释代码prop吗?
主要用例是为深层属性编写通用get函数.具有类似功能的东西_.get.我试图避免这种情况:
if (a && a.b …Run Code Online (Sandbox Code Playgroud)