我在MacOS(M2 GPU)的haskell中开发vulkan应用程序。
代码width = realToFrac (width (swapchainExtent :: Extent2D))
在以下项目(vulkan
)https://github.com/expipiplus1/vulkan/blob/2007a6ebca9a585028163a850bcedef856fc1e94/examples/sdl-triangle/Main.hs#L283C66-L283C74
在ghc 8.10.7
中编译成功。
但是ghc 9.6.3
中的错误。
错误消息为
/Users/liuzichao/Hulkan/test/Main.hs:283:40: error:
Ambiguous occurrence ‘width’
It could refer to
either the field ‘width’ of record ‘Viewport’,
imported from ‘Vulkan.Core10’ at test/Main.hs:36:1-30
(and originally defined in ‘Vulkan.Core10.Pipeline’)
or the field ‘width’ of record ‘FramebufferCreateInfo’,
imported from ‘Vulkan.Core10’ at test/Main.hs:36:1-30
(and originally defined in ‘Vulkan.Core10.Pass’)
or the field ‘width’ of record ‘Extent3D’,
imported from ‘Vulkan.Core10’ at test/Main.hs:36:1-30
(and originally defined in ‘Vulkan.Core10.FundamentalTypes’)
or the field ‘width’ of record ‘Extent2D’,
imported from ‘Vulkan.Core10’ at test/Main.hs:36:1-30
(and originally defined in ‘Vulkan.Core10.FundamentalTypes’)
|
283 | , width = realToFrac (width (swapchainExtent :: Extent2D))
|
字符串
为什么会发生这种情况?如果ghc 9.6.3
与ghc 8.10.7
有什么不同?
1条答案
按热度按时间dw1jzc5e1#
是的,我遇到了同样的问题,试图遵循一些Vulkan的例子。
基于this proposal的记录字段正在进行大量更改,这需要模糊的字段名称变得更加模糊。我发现GHC更改日志中的文档不完整,并且对于该提案的哪些部分正在与GHC的哪些版本一起推出感到困惑。
但是,GHC 8.10.7接受以下程序:
字符串
在GHC 9.2.1中编译但抛出一些警告(与使用更新语法
width = ...
而不是width (r :: Rect)
访问有关),并被9.4.1完全拒绝:型
最简单的修复方法是使用
OverloadedRecordDot
扩展(从GHC 9.2.0开始可用),它允许您编写:型
这仍然会在
width = ...
更新部分抛出警告,但它会编译。对于上面的示例,以下方法有效:
型
并且不生成警告,因为这是构造函数调用的一部分,而不是记录更新。