fromNotes :: [(Char, Int)] -> [Double] fromNotes = map freq where freq (x,y) = 440 * 2**((midi 'A' 4 - midi x y)/12) midi c o = o * 12 + getIndex c s 0 + 12 s = "CcDdEFfGgAaB" getIndex c (x:xs) i | c == x = i | otherwise = getIndex c xs (i+1)
The code gives the error:
* Couldn't match type `Int' with `Double' Expected type: [(Char, Int)] -> [Double] Actual type: [(Char, Double)] -> [Double]
From what i can tell the problem is in
midi 'A' 4 - midi x y.
But why is Haskell saying the actual type is a Double?
freqmust return a
2**((midi 'A' 4 - midi x y)/12)must be a
midimust return a
o * 12must be a
- the second argument to
midimust be a
midi x ymust be a
freqmust take a
Doubleas the second part of its tuple.
You can use
fromIntegral :: Int -> Double at almost any step in that chain to fix things up. It's probably simplest to do it right away, as in
freq (x, y) = ... midi x (fromIntegral y) ...