已经问过如何Consumer
在 aPipe
Consumer'
中运行 a 的问题,但随后提供的答案需要多态类型同义词:
{-# LANGUAGE RankNTypes #-}
import Pipes
toPipe :: Monad m => Consumer' i m o -> Pipe i o m ()
toPipe consumer = consumer >>= yield
现在,我遇到的问题是 in Pipes.Vector
,toVector
使用单态Consumer
同义词:
toVector :: (PrimMonad m, MVector (Mutable v) e) => Consumer e (ToVector v e m) r
因此toPipe
,该答案中的功能在这种情况下将不起作用:
{-# LANGUAGE RankNTypes #-}
module VectorPipe where
import Control.Monad.Primitive (PrimMonad)
import qualified Data.Vector.Generic as G
import Pipes
import Pipes.Vector
toPipe :: Monad m => Consumer' i m o -> Pipe i o m ()
toPipe consumer = consumer >>= yield
vectorPipe :: (PrimMonad m, G.Vector v a) => Pipe a (v a) m ()
vectorPipe = toPipe (runToVectorP toVector)
{-
VectorPipe.hs:13:35-42: Could not deduce (y' ~ ()) …
from the context (PrimMonad m, G.Vector v a)
bound by the type signature for
vectorPipe :: (PrimMonad m, G.Vector v a) => Pipe a (v a) m ()
at /Users/casillas/GitHub/tau-sigma/VectorPipe.hs:12:15-62
‘y'’ is a rigid type variable bound by
a type expected by the context: Proxy () a y' y m (v a)
at /Users/casillas/GitHub/tau-sigma/VectorPipe.hs:13:14
Expected type: Proxy () a y' y (ToVector v a m) r0
Actual type: Consumer a (ToVector v a m) r0
In the first argument of ‘runToVectorP’, namely ‘toVector’
In the first argument of ‘toPipe’, namely ‘(runToVectorP toVector)’
VectorPipe.hs:13:35-42: Could not deduce (y ~ X) …
from the context (PrimMonad m, G.Vector v a)
bound by the type signature for
vectorPipe :: (PrimMonad m, G.Vector v a) => Pipe a (v a) m ()
at /Users/casillas/GitHub/tau-sigma/VectorPipe.hs:12:15-62
‘y’ is a rigid type variable bound by
a type expected by the context: Proxy () a y' y m (v a)
at /Users/casillas/GitHub/tau-sigma/VectorPipe.hs:13:14
Expected type: Proxy () a y' y (ToVector v a m) r0
Actual type: Consumer a (ToVector v a m) r0
In the first argument of ‘runToVectorP’, namely ‘toVector’
In the first argument of ‘toPipe’, namely ‘(runToVectorP toVector)’
Compilation failed.
-}
有什么建议么?toVector
也许是不必要地狭窄的签名?(我是一个太多的管道菜鸟来告诉... 编辑:我尝试将签名更改pipes-vector
为Consumer'
; 代码编译,但它看起来vectorPipe
永远不会产生。)