是否有相当于ofoldlUnwrap扫描未装箱的载体?

时间:2017-08-16 10:31:00

标签: haskell fold

是否可以使用Control.Foldl foldl作为scanl作为未装箱或通用的vector

根据purely ofoldlUnwrap文档中的建议,绝对可以使用foldl折叠未装箱的向量。但是扫描也不可能。

天真的方法失败了,因为(至少据我所知)没有办法设置中间结果的类型:

scanVG :: forall v a b . (VG.Vector v a, VG.Vector v b)
       => F.Fold a b -> v a -> v b
scanVG (F.Fold step begin done)  = VG.map done . VG.scanl' step begin

===>

• Could not deduce (Vector v x) arising from a use of ‘map’
  from the context: (Vector v a, Vector v b)
    bound by the type signature for:
               scanVG :: (Vector v a, Vector v b) => Fold a b -> v a -> v b
    at src/File.hs:(162,1)-(163,34)
  Possible fix:
    add (Vector v x) to the context of the data constructor ‘Fold’
• In the first argument of ‘(.)’, namely ‘map done’
  In the expression: map done . scanl' step begin
  In an equation for ‘scanVG’:
      scanVG (Fold step begin done) = map done . scanl' step begin

现在我正在转换为盒装载体,并希望融合能够消除所涉及的开销。

0 个答案:

没有答案