以下代码
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module Function where
import qualified Data.Vector.Unboxed as V
import Control.Monad
type Function = V.Vector Double
instance Num Function where
(+) = liftM2 (+)
(*) = liftM2 (*)
negate = fmap negate
Run Code Online (Sandbox Code Playgroud)
返回错误,如
No instance for (Monad V.Vector)
arising from a use of `liftM2'
Run Code Online (Sandbox Code Playgroud)
虽然在文档中说Vector是Monad的一个实例.
Unboxed Vector不是.的实例Monad.请注意,vector包会导出许多不同类型的调用Vector.Data.Vector.Unboxed.Vector/= Data.Vector.Vector/= Data.Vector.Storable.Vector.
| 归档时间: |
|
| 查看次数: |
159 次 |
| 最近记录: |