【发布时间】:2017-05-20 06:44:07
【问题描述】:
这可能是一个非常基本的问题,但我已经四处搜索,似乎找不到答案。
我想使用未装箱的向量来表示一个二维列表。使用法线向量很容易做到这一点:
> 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]
但我似乎无法理解如何避免这种情况。
提前致谢!
【问题讨论】:
-
您可能想使用
V.Vector (U.Vector a)。如果内部向量不是非常小,这仍然可以为您提供未装箱向量的大部分性能优势。或者,如果内部向量总是相同的小尺寸,请使用不可装箱的固定尺寸类型,例如来自linear package。