0

Edit: Sorry, just stupidity on my part. I 'm using the 7.6.3 Platform, but reading online docs for 'latest', and I just did this:

>: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'

and look, no applicative instance. Sorry for the bother, and thanks to bheklilr for asking me about versioning, which I just spaced on.

The following confuses me. There certainly seems to be an instance defining (<*>) sensibly for Seq:

instance Applicative Seq where
pure = singleton
fs <*> xs = foldl' add empty fs
  where add ys f = ys >< fmap f xs

Yet, this happens:

>: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)

Using a singleton produces slightly different typing (no Enum qualification) and hence a slightly different error.

>: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]

The type Seq (a -> a) would seem to me to conform to the f (a -> b) required by (<*>) :: Applicative f => f (a -> b) -> f a -> f b.

I'm sure this is simple and I'll be embarrassed for asking, but thanks in advance.

  • 1
    What version of `base` are you using? I'm on GHC 7.8.3 and base-4.7.0.1 and I have an applicative instance for `Seq`. – bheklilr Jan 07 '15 at 17:11
  • Yeah, I'm not on my normal machine and its 7.6.3/4.6.0.1, but I was reading the docs online for latest, which is what confused me. I do, as predicted, feel stupid. Thanks. – confunderated Jan 07 '15 at 17:59

0 Answers0