编辑:对不起,我的愚蠢。我正在使用7.6.3平台,但是阅读最新版本的在线文档,我就这样做了:
>:i Seq
newtype Seq a
= Data.Sequence.Seq (Data.Sequence.FingerTree
(Data.Sequence.Elem a))
-- Defined in `Data.Sequence'
instance Eq a => Eq (Seq a) -- Defined in `Data.Sequence'
instance Monad Seq -- Defined in `Data.Sequence'
instance Functor Seq -- Defined in `Data.Sequence'
instance Ord a => Ord (Seq a) -- Defined in `Data.Sequence'
instance Read a => Read (Seq a) -- Defined in `Data.Sequence'
instance Show a => Show (Seq a) -- Defined in `Data.Sequence'
并且看,没有应用实例。很抱歉打扰了,感谢bheklilr向我询问版本控制,我只是间隔开来。
以下让我感到困惑。肯定似乎有一个为Seq明确定义(< *>)的实例:
instance Applicative Seq where
pure = singleton
fs <*> xs = foldl' add empty fs
where add ys f = ys >< fmap f xs
然而,这种情况发生了:
>:m + Data.Sequence Control.Applicative
>(*) <$> [1..4] <*> [3..4]
[3,4,6,8,9,12,12,16]
>(*) <$> fromList [1..4] <*> fromList [3..4]
<interactive>:58:25:
No instance for (Applicative Seq) arising from a use of `<*>'
Possible fix: add an instance declaration for (Applicative Seq)
In the expression: (*) <$> fromList [1 .. 4] <*> fromList [3 .. 4]
In an equation for `it':
it = (*) <$> fromList [1 .. 4] <*> fromList [3 .. 4]
>:t (*) <$> fromList [1..4]
(*) <$> fromList [1..4] :: (Enum a, Num a) => Seq (a -> a)
使用单例产生的输入略有不同(没有枚举限定),因此错误略有不同。
>:t (*) <$> singleton 3
(*) <$> singleton 3 :: Num a => Seq (a -> a)
>:t (*) <$> singleton 3 <*> fromList [3 .. 4]
<interactive>:1:21:
Could not deduce (Applicative Seq) arising from a use of `<*>'
from the context (Enum b, Num b)
bound by the inferred type of it :: (Enum b, Num b) => Seq b
at Top level
Possible fix: add an instance declaration for (Applicative Seq)
In the expression: (*) <$> singleton 3 <*> fromList [3 .. 4]
我认为Seq (a -> a)
类型符合f (a -> b)
所要求的(<*>) :: Applicative f => f (a -> b) -> f a -> f b
。
我确信这很简单,我会因为询问而感到尴尬,但是事先谢谢。