When something like Num [b]
turns up in an inferred type, you can be quite sure there appears a numerical literal where GHC expects a list, or a list turns up as one of the arguments to a numerical operator. And indeed:
... ys + map (*(0.5*h)) k1 ...
both ys
and k1
are lists, but +
is numerical addition.
Perhaps you're trying to use ++
here, but let me tell you your whole approach is less than nice. Why do you accept [xs, ys]
as a always–two-element list? Start with a reasonable signature, something similar to
rk4 :: (Floating a, Floating t) => [a -> t -> a] -> a -> [t] -> [a]`
Write that down first of all, and then start to implement the function from the outside to the inside, first leaving more local subexpressions undefined
. Compile in frequent intervals, and when an error turns up you'll immediately see where.
BTW. It's not really great to use Haskell lists for implementing mathematical vectors, on any level. The "right" version of Runge-Kutta, IMO, has a signature along the lines
rk4 :: (VectorSpace v, t ~ Scalar v, Floating t)
=> (v -> t -> v) -> v -> [t] -> [v]