Question: I am using Haskell and have declared a `Vector` as

```
data Vector = Vector [Double]

```

Now, I want to declare the `dot` product of two vectors as

```
dot :: Vector -> Vector -> Double
dot a b = sum $ a * b -- I already wrote Vector as an instance of Num for *.

```

But, the problem is, I receive the error

```
Couldn't match expected type [a0] with actual type Vector

```

I assume this means that `sum` doesn't know how to operate on a `Vector`. What is the best way to approach this issue?

Answer: 
So I've noticed you're not using standard vectors. I'd suggest switching to them, but if you really don't want to,

```
 toList :: Vector -> [Double]
 toList (Vector a) = a

```

and use

```
dot a b = sum . toList $ a * b

```

If you switch to standard vectors you have 3 choices

1. Turn your `Vector` to a list,

```
import Data.Vector as V
dot a b = sum . V.toList $ a * b

```

Simple, but needlessly slow.
2. Use a more general `sum`

```
import Data.Foldable as F
dot a b = F.sum $ a * b

```

Flexible, can lead to weird type errors since we're relying on another typeclass.
3. Use a different, specific (the fancy word is monomorphic) `sum`

```
 import Data.Vector as V
 dot a b = V.sum $ a * b

```

Simplest, but of course, if you stop using vectors this will break.

I'd recommend option 3, no need to be overly general yet.
Since you aren't using `Data.Vector` vectors, you can't actually make `sum` work directly on your data type, since it's type is

```
sum :: Num a => [a] -> a

```

and you're giving it `Vector [Double]` instead of a `Num a => [a]`. You'll have to extract list inside the vector first:

```
toList :: Vector -> [Double]
toList (Vector vals) = vals

dot :: Vector -> Vector -> Double
dot a b = sum . toList $ a * b

```

That being said, you should probably just use the vectors provided by `Data.Vector`, or at the very least you should define your `Vector` type as

```
{-# LANGUAGE DeriveFunctor #-}

import Control.Applicative

data Vector a = Vector [a] deriving (Eq, Ord, Show, Functor)

instance Applicative Vector where
    pure a = Vector [a]
    (Vector fs) <*> (Vector xs) = Vector $ zipWith ($) fs xs

instance Num a => Num (Vector a) where
    a + b = (+) <$> a <*> b
    a * b = (*) <$> a <*> b
    -- etc.

```

Then you can have `Vector Int`, `Vector Double`, even `Vector (Int -> Double)`, and since it's now a `Functor` and an `Applicative`, you can do a lot more with it, as this example suggests.