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.
To a create a dot function you could do

```
data Vector = Vector [Double]

dot :: Vector -> Vector -> Double
dot (Vector a) (Vector b) = sum $ zipWith (*) a b

```

This way 'a' and 'b' are now the [Double] inside of the Vector and not the Vector its self.

Step-by-step:

```
dot (Vector [1,2]) (Vector [3,4]) = sum $ zipWith (*) [1,2] [3,4]

= sum $ zipWith (*) [1,2] [3,4]
= sum $ [1*3, 2*4]
= 1*3 + 2*4
= 3 + 8
= 11

```