作者:半宅半学 | 来源:互联网 | 2023-02-03 13:56
这可能是一个非常基本的问题,但我已经四处寻找,似乎无法找到答案.
我想使用未装箱的矢量来表示2D列表.使用法线向量很容易做到这一点:
> import qualified Data.Vector as V
> V.fromList [V.fromList [1..5]]
[[1,2,3,4,5]]
但是,如果我尝试使用未装箱的矢量:
> import qualified Data.Vector.Unboxed as U
> U.fromList [U.fromList [1..5]]
我收到以下错误:
• Non type-variable argument
in the constraint: U.Unbox (U.Vector a)
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a.
(U.Unbox (U.Vector a), U.Unbox a, Num a, Enum a) =>
U.Vector (U.Vector a)
我怀疑它与此有关:
> V.fromList [1..5]
[1,2,3,4,5]
而
> U.fromList [1..5]
[1.0,2.0,3.0,4.0,5.0]
但我似乎无法理解如何避免这种情况.
提前致谢!
1> chi..:
好吧,我们可以开始遵循编译器给出的建议:
> :set -XFlexibleContexts
然而:
> U.fromList [U.fromList [1..5]]
:10:1: error:
• No instance for (U.Unbox (U.Vector a0))
arising from a use of ‘print’
这里的问题是您无法取消装箱矢量(即使它是未装箱的数据).要取消装箱数据类型,您需要精确描述字节布局,包括其大小.但是矢量没有大小.考虑例如
U.fromList [U.fromList [1..5], U.fromList [1..7]]
即使在C中,这也需要一个"锯齿状"矩阵,通常用指针(=拳击)表示.