是否有任何类型安全的方法来编写函数
bi f a b = (f a, f b)
Run Code Online (Sandbox Code Playgroud)
这样就可以像这样使用它:
x1 :: (Integer, Char)
x1 = bi head [2,3] "45"
x2 :: (Integer, Char)
x2 = bi fst (2,'3') ('4',5)
x3 :: (Integer, Double)
x3 = bi (1+) 2 3.45
Run Code Online (Sandbox Code Playgroud)
?在rank-n-types例子中总有一些更简单的东西
g :: (forall a. a -> a) -> a -> a -> (a, a)
g f a b = (f a, f b)
Run Code Online (Sandbox Code Playgroud) 我对servant感到很兴奋,只要不妨碍它,我就可以使用它的内部类型魔法,唯一令我困惑的是它在公共API中使用了一个类型代理.这是代码:
serve :: HasServer layout => Proxy layout -> Server layout -> Application
serve p server = toApplication (runRouter (route p (return (RR (Right server)))))
Run Code Online (Sandbox Code Playgroud)
据我所知,类型代理是相当简单的事情,当你没有这种类型的值时需要携带一个类型.那么为什么在Server的类型参数中已有布局类型时传递一个承载布局类型的代理?我已经尝试克隆servant的repo并将代码更改为:
{-# LANGUAGE ScopedTypeVariables #-}
serve :: forall layout . HasServer layout => Server layout -> Application
serve server = toApplication (runRouter (route p (return (RR (Right server)))))
where
p :: Proxy layout
p = Proxy
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,这无法编译(告诉布局类型不匹配).但是为什么,我的本地p不应该与服务器具有相同的布局类型(打开ScopedTypeVariables)?
出于某种原因,我需要欺骗Haskell执行一个无限循环,而不是仅仅检测它并退出<<loop>>,但它太聪明了.是否有任何方便的例子,其中循环是由严格注释(!)引起的,还是我可以关闭循环检测?目前我在做
x = x + y
y = x + y
inf !n = 0
main = do
print $ inf x
Run Code Online (Sandbox Code Playgroud) VirtualQueryEx的dwLength参数的目的是什么?这里描述如下:
lpBuffer [out]指向MEMORY_BASIC_INFORMATION结构的指针,其中返回有关指定页面范围的信息.
dwLength [in] lpBuffer参数指向的缓冲区大小,以字节为单位.
除此之外,有什么理由可以使用sizeof(MEMORY_BASIC_INFORMATION)吗?